VSCode FileNotFoundError - python

I am trying to create a 2D arcade style game for a project in school using Python Arcade in VSCode, but I have issues correctly locating a map I created on a map editor.
Both the game code and map file are situated in the same main folder, with the map being placed in a sub-folder within the main folder.
I have used this line of code to specify the map location:
# Map name
map_name = ("maps/map1_level_{}.tmx.".format(level))
This is the error:
C:\Users\frag>python c:/Users/frag/Documents/game/arcade_game.py
Traceback (most recent call last):
File "c:/Users/frag/Documents/game/arcade_game.py", line 310, in <module>
main()
File "c:/Users/frag/Documents/game/arcade_game.py", line 305, in main
window.setup(window.level)
File "c:/Users/frag/Documents/game/arcade_game.py", line 120, in setup
my_map = arcade.tilemap.read_tmx(map_name)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\arcade\tilemap.py", line 56, in read_tmx
tmx_file = resolve_resource_path(tmx_file)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\arcade\resources\__init__.py", line 30, in resolve_resource_path
raise FileNotFoundError(f"Cannot locate resource : {path}")
FileNotFoundError: Cannot locate resource : maps\map1_level_1.tmx

try this map_name = ("./maps/map1_level_{}.tmx.".format(level))

Fixed the issue by specifying the working absolute path:
import os
os.chdir('C:/Users/frag/Documents/game')

Related

Problem with adding fonts in python script

e, Hi does anyone know, I don't understand how to add my own font for text into some python script for image procesing? I found in code fontlist.txt -> a file that is used as text source. So there I put my .ttf fonts that I downloaded from here: https://www.1001fonts.com/text-fonts.html?page=1&fbclid=IwAR395plHPNmZemLoKmvpedbqRv0z8pUVU66np7LLWzia14GrAKWcZB1H5o4 and then terminal shows me and error :
Traceback (most recent call last):
File "/home/isus/Dokumenti/WET/SynthText-python3/synthgen.py", line 669, in render_text
regions['homography_inv'][ireg])
File "/home/isus/Dokumenti/WET/SynthText-python3/synthgen.py", line 506, in place_text
render_res = self.text_renderer.render_sample(font,collision_mask)
File "/home/isus/Dokumenti/WET/SynthText-python3/text_utils.py", line 414, in render_sample
f_h = self.font_state.get_font_size(font, f_h_px)
File "/home/isus/Dokumenti/WET/SynthText-python3/text_utils.py", line 534, in get_font_size
m = self.font_model[font.name]
KeyError: 'Fabiolo'
Traceback (most recent call last):
File "/home/isus/Dokumenti/WET/SynthText-python3/synthgen.py", line 669, in render_text
regions['homography_inv'][ireg])
File "/home/isus/Dokumenti/WET/SynthText-python3/synthgen.py", line 504, in place_text
font = self.text_renderer.font_state.init_font(font)
File "/home/isus/Dokumenti/WET/SynthText-python3/text_utils.py", line 565, in init_font
font = freetype.Font(fs['font'], size=fs['size'])
OSError: Failed to load font: unknown file format
This 'Fabiolo' is a name of font.
How Failed to load font: unknown file format? I'm using .ttf fonts like they who made a script. Maybe ubuntu supports some certain fonts. I'm using UBUNTU 18.04.
When I use the upper one (fontlist1.txt - mine) there shows an error.
When I use the bottom one (fontlist.txt - originally from script) that works fine everytime.
Here you can see how I add paths and names into fontlist1.txt
I also add the font names like 'Fabiolo', 'Halida Sans', ... into Font Manager but still nothing, shows the same errors.

reading pg_dump file occurs at open the file

I'm using the pgdumplib lib. Unfortunately there is an error, when I'm trying to open the file. The file is in the same folder as the python script. I'm using Python 3.7
Code:
import pgdumplib
dump = pgdumplib.load('test.dump')
print('Database: {}'.format(dump.toc.dbname))
print('Archive Timestamp: {}'.format(dump.toc.timestamp))
print('Server Version: {}'.format(dump.toc.server_version))
print('Dump Version: {}'.format(dump.toc.dump_version))
for line in dump.table_data('public', 'pgbench_accounts'):
print(line)
Error:
Traceback (most recent call last):
File "C:/Users/user/data/test.py", line 3, in <module>
dump = pgdumplib.load('test.dump')
File "C:\Users\user\venv\data\lib\site-packages\pgdumplib\__init__.py", line 24, in load
return dump.Dump(converter=converter).load(filepath)
File "C:\Users\user\venv\data\lib\site-packages\pgdumplib\dump.py", line 228, in load
raise ValueError('Path {!r} does not exist'.format(path))
ValueError: Path 'test.dump' does not exist
If you are running your code from C:/Users/user/700Joach/project/ and you have the following line in your script:
dump = pgdumplib.load('test.dump')
Then, python would look for the following path to open test.dump:
C:/Users/user/700Joach/project/test.dump
Namely, this part: load('test.dump') internally is forging a relative path to test.dump.
You can do several things to resolve the issue. Either move test.dump to the directory from which you are executing your code. Or, provide an absolute path to your test.dump as follows:
dump = pgdumplib.load('C:/Users/user/700Joach/project/test.dump')

gensim file not found error

I am executing the following line:
id2word = gensim.corpora.Dictionary.load_from_text('wiki_en_wordids.txt')
This code is available at "https://radimrehurek.com/gensim/wiki.html". I downloaded the wikipedia corpus and generated the required files and wiki_en_wordids.txt is one of those files. This file is available in the following location:
~/gensim/results/wiki_en
So when i execute the code mentioned above I get the following error:
Traceback (most recent call last):
File "~\Python\Python36-32\temp.py", line 5, in <module>
id2word = gensim.corpora.Dictionary.load_from_text('wiki_en_wordids.txt')
File "~\Python\Python36-32\lib\site-packages\gensim\corpora\dictionary.py", line 344, in load_from_text
with utils.smart_open(fname) as f:
File "~\Python\Python36-32\lib\site-packages\smart_open\smart_open_lib.py", line 129, in smart_open
return file_smart_open(parsed_uri.uri_path, mode)
File "~\Python\Python36-32\lib\site-packages\smart_open\smart_open_lib.py", line 613, in file_smart_open
return open(fname, mode)
FileNotFoundError: [Errno 2] No such file or directory: 'wiki_en_wordids.txt'
Even though the file is available in the required location I get that error. Should I place the file in any other location? How do I determine what the right location is?
The code requires an absolute path here. Relative path should be used when entire operation is carried out in the same directory location, but in this case, the file name is passed as argument to some other function which is located at different location.
One way to handle this situation is using abspath -
import os
id2word = gensim.corpora.Dictionary.load_from_text(os.path.abspath('wiki_en_wordids.txt'))

How to solve "rospkg.common.ResourceNotFound" in ros-indigo-ubuntu (14.04)?

I am doing face detection robot using ros. I'm having trouble running the face detection node and am getting the error below:
arun#arun-Aspire-V5-121:~$ source /usr/share/setup.launch
arun#arun-Aspire-V5-121:~$ source ./ws1/devel/setup.bash
arun#arun-Aspire-V5-121:~$ rosrun exp2 face.py
Traceback (most recent call last):
File "/home/arun/ws1/src/exp2/scripts/face.py", line 4, in <module>
roslib.load_manifest('rosopencv')
File "/opt/ros/indigo/lib/python2.7/dist-packages/roslib/launcher.py", line 62, in load_manifest
sys.path = _generate_python_path(package_name, _rospack) + sys.path
File "/opt/ros/indigo/lib/python2.7/dist-packages/roslib/launcher.py", line 93, in _generate_python_path
m = rospack.get_manifest(pkg)
File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 164, in get_manifest
return self._load_manifest(name)
File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 208, in _load_manifest
retval = self._manifests[name] = parse_manifest_file(self.get_path(name), self._manifest_name, rospack=self)
File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 200, in get_path
raise ResourceNotFound(name, ros_paths=self._ros_paths)
rospkg.common.ResourceNotFound: rosopencv
ROS path [0]=/opt/ros/indigo/share/ros
ROS path [1]=/home/arun/ws1/src
ROS path [2]=/opt/ros/indigo/share
ROS path [3]=/opt/ros/indigo/stacks
Actually you are missing python libraries in your system, you can download and install this first then you may be able to run your script.

Function cannot open file after py2exe compile

I'm using rdkit.
After a build using py2exe, when I call the Draw.MolToImage method there is an error:
Warning: unable to load font metrics from dir
C:\pythonApp\dist\library.zip\rd
kit\sping\PIL\pilfonts
Traceback (most recent call last):
File "app.py", line 470, in <module>
img=Draw.MolToImage(part[i])
File "rdkit\Chem\Draw\__init__.pyc", line 124, in MolToImage
File "rdkit\Chem\Draw\MolDrawing.pyc", line 536, in AddMol
File "rdkit\Chem\Draw\MolDrawing.pyc", line 351, in _drawLabel
File "rdkit\Chem\Draw\spingCanvas.pyc", line 74, in addCanvasText
File "rdkit\sping\PIL\pidPIL.pyc", line 333, in drawString
ValueError: bad font: Font(12,0,0,0,'helvetica')`
There is no difference if I put these files into library.zip (to \rdkit\sping\PIL\pilfonts) or just into the dist folder and change paths in pidPIL.py to valid; the application still cannot open metrics.dat.
Without the py2exe conversion, everything works perfectly.
Are you using 'data_files' in your setup.py to include the pilfonts folder?
E.g. something along these lines:
setup(
data_files = [("pilfonts", glob.glob("\rdkit\sping\PIL\pilfonts\*.*"),
options = {"py2exe": {"compressed": 2,
# etc etc
)

Categories