got error for set map path in visual studio code - python

I'm try to set path for map using this line
world.save('maps_htmls/world_empty.html')
and i got error :-
File "e:\Monty Python Project\ALL TASK\Task\Individual programming project.py", line 35, in <module>
world.save('../maps_htmls/world_empty.html')
File "C:\Users\singh\AppData\Local\Programs\Python\Python310\lib\site-packages\branca\element.py", line 164, in save
fid = open(outfile, 'wb')
FileNotFoundError: [Errno 2] No such file or directory: '../maps_htmls/world_empty.html'

Related

Getting filenotfound error when trying to open a h5 file

I have a h5 file that contains the "catvnoncat" dataset. when I try to run the following code, I get an error which I will include at the bottom. I have tried getting the dataset from three different sources to exclude to possibility of a corrupted file.
What I would like to know is what is causing the problem?
# My Code
import h5py
train_dataset = h5py.File('train_catvnoncat.h5', "r")
# The Error
Traceback (most recent call last):
File "f:\Downloads\Compressed\coursera-deep-learning-specialization-master_2\coursera-deep-learning-specialization-master\C1 - Neural Networks and Deep Learning\Week 2\Logistic Regression as a Neural Network\lr_utils.py", line 4, in <module>
train_dataset = h5py.File('train_catvnoncat.h5', "r")
File "C:\Users\Mohsen\AppData\Local\Programs\Python\Python39\lib\site-packages\h5py\_hl\files.py", line 507, in __init__
fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)
File "C:\Users\Mohsen\AppData\Local\Programs\Python\Python39\lib\site-packages\h5py\_hl\files.py", line 220, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5f.pyx", line 106, in h5py.h5f.open
FileNotFoundError: [Errno 2] Unable to open file (unable to open file: name = 'train_catvnoncat.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)
Your code is looking in the current directory which is not where the file is.
Based on the error message, it looks like you are on windows. Is the file 'train_catvnoncat.h5' in your Downloads folder? Find that file on your system and copy the full path. You can then update this:
train_dataset = h5py.File('train_catvnoncat.h5', "r")
to something that contains the full path. Similar to this:
train_dataset = h5py.File('C:/Users/Moshen/Downloads/train_catvnoncat.h5', "r")
Pay attention to the slashes and make sure you update the file path to the actual value.

PermissionError: [Errno 13] Permission denied: Python

I have a script that is called from DJango, but it doesn't execute instead it gives PermissionError: [Errno 13] Permission denied. I'm using CMD on Windows as admin.
Here is how I'm calling:
cmd = os.path.join(os.getcwd(), "D:/commerceTest/cs50-commerceM/Photo/GFPGAN/inference_gfpgan.py --upscale 2 --model_path D:/commerceTest/cs50-commerceM/Photo/GFPGAN/experiments/pretrained_models/ --test_path inputs/whole_imgs/GFPGANCleanv1-NoCE-C2.pth --save_root D:/commerceTest/cs50-commerceM/Photo/GFPGAN/results")
#os.system("python D:/commerceTest/cs50-commerceM/Photo/GFPGAN/inference_gfpgan.py --upscale 2 --model_path D:/commerceTest/cs50-commerceM/Photo/GFPGAN/experiments/pretrained_models/ --test_path inputs/whole_imgs/GFPGANCleanv1-NoCE-C2.pth --save_root D:/commerceTest/cs50-commerceM/Photo/GFPGAN/results")
os.system('{} {}'.format('python', cmd))
Here is the message I received:
Traceback (most recent call last):
File "D:\commerceTest\cs50-commerceM\Photo\GFPGAN\inference_gfpgan.py", line 98, in <module>
main()
File "D:\commerceTest\cs50-commerceM\Photo\GFPGAN\inference_gfpgan.py", line 52, in main
restorer = GFPGANer(
File "D:\commerceTest\cs50-commerceM\Photo\GFPGAN\gfpgan\utils.py", line 60, in __init__
loadnet = torch.load(model_path)
File "D:\Users\rapha\AppData\Local\Programs\Python\Python39\lib\site-packages\torch\serialization.py", line 594, in load
with _open_file_like(f, 'rb') as opened_file:
File "D:\Users\rapha\AppData\Local\Programs\Python\Python39\lib\site-packages\torch\serialization.py", line 230, in _open_file_like
return _open_file(name_or_buffer, mode)
File "D:\Users\rapha\AppData\Local\Programs\Python\Python39\lib\site-packages\torch\serialization.py", line 211, in __init__
super(_open_file, self).__init__(open(name, mode))
PermissionError: [Errno 13] Permission denied: 'D:/commerceTest/cs50-commerceM/Photo/GFPGAN/experiments/pretrained_models/'
I can only guess here but the error that you are getting is because Python is trying to open a directory as a file (which won't work).
It looks like the path that you are passing in to --model_path is a directory but torch.load() expects a file, that would explain it.
I would start with understanding what exactly the script inference_gfpgan.py does and how it works.

Getting File not found error" with zipfile module python

File "import.py", line 64, in unzip
File "zipfile.py", line 1647, in extractall
File "zipfile.py", line 1701, in _extract_member
FileNotFoundError: [Errno 2] No such file or directory:
Getting this error for a file while unzipping, The character length for the entire path is 271 characters. Can this be due to long path >? Longpath value is 1 in the registry for Longpathenabled variable.

cannot write file with full path in Python

I am using Pandas on Mac, to read and write a CSV file, and the weird thing is when using full path, it has error and when using just a file name, it works. I post my code which works and which not works in my comments below, and also detailed error messages. Anyone have any good ideas?
sourceDf = pd.read_csv(path_to_csv)
sourceDf['nameFull'] = sourceDf['nameFirst'] + ' ' + sourceDf['nameLast']
sourceDf.to_csv('newMaster.csv') # working
sourceDf.to_csv('~/Downloads/newMaster.csv') # not working
Traceback (most recent call last):
File "/Users/foo/PycharmProjects/DataWranglingTest/CSVTest1.py", line 36, in <module>
add_full_name(path_to_csv, path_to_new_csv)
File "/Users/foo/PycharmProjects/DataWranglingTest/CSVTest1.py", line 28, in add_full_name
sourceDf.to_csv('~/Downloads/newMaster.csv')
File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.py", line 1189, in to_csv
formatter.save()
File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/format.py", line 1442, in save
encoding=self.encoding)
File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/common.py", line 2831, in _get_handle
f = open(path, mode)
IOError: [Errno 2] No such file or directory: '~/Downloads/newMaster.csv'
Tried to use prefix r, but not working,
path_to_csv = r'~/Downloads/Master.csv'
path_to_new_csv = r'~/Downloads/Master_new.csv'
File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.py", line 1189, in to_csv
formatter.save()
File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/format.py", line 1442, in save
encoding=self.encoding)
File "/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/common.py", line 2831, in _get_handle
f = open(path, mode)
IOError: [Errno 2] No such file or directory: '~/Downloads/Master_new.csv'
thanks in advance,
Lin
Try using os.path.join().
import os
(...)
output_filename = 'newMaster.csv'
output_path = os.path.join('Downloads', output_filename)
(...)
sourceDf.to_csv(output_path)
Use the same methodology to point pandas.read_csv() in the right direction.
You didn't specify python version.
On 3.4 you can use pathlib, otherwise use os.path.join() or quoting:
sourceDf.to_csv(r'~/Downloads/newMaster.csv')
Notice the r.
The problem is that /n is newline, which is not allowed in a path.

IOError: [Errno 2] No such file or directory: 'Book1.xls'

Traceback (most recent call last):
File "C:/my_python/read1.py", line 3, in <module>
book = open_workbook('Book1.xls',on_demand=True)
File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 449, in open_workbook
ragged_rows=ragged_rows,
File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 941, in biff2_8_load
f = open(filename, open_mode)
IOError: [Errno 2] No such file or directory: 'Book1.xls'
I am getting this error message in python while trying to open an excel sheet.....How can i solve this ?
Either make sure Book1.xls is in "C:\my_python\", which is also where your script is, or use the full path to where Bool1.xls is located. For example:
book = open_workbook('C:\\Users\\Jeeva\\Documents\\Book1.xls',on_demand=True)

Categories