file not found error, though file is in proper place - python-3.x

C:\Users\ebena\PycharmProjects\untitled2\venv\Scripts\python.exe C:/Users/ebena/PycharmProjects/untitled2/trial.py
Traceback (most recent call last):
File "C:/Users/ebena/PycharmProjects/untitled2/trial.py", line 5, in <module>
image = Image.open("book background.jpeg")
File "C:\Users\ebena\PycharmProjects\untitled2\venv\lib\site-packages\PIL\Image.py", line 2878, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'book background.jpeg'
python cannot access these files and says they do not exist or file not found

Change the name of the file to book_background.jpeg

Related

Python: PermissionError: [Errno 13] with copy_tree function in windows

Im just copying all files and subfolders from an specific directory using the function distutils.dir_util.copy_tree in Windows:
from distutils.dir_util import copy_tree
from datetime import datetime
directories_to_backup = {
'folder_a' : 'e:\\folder_a',
}
now = datetime.now()
backup_name_folder = now.strftime("%Y%m%d-%H%M")
for name_folder, path_folder in directories_to_backup.items():
print(f'Backuping up the folder {name_folder}')
backup_full_path = f't:\\zzzBackup\\{backup_name_folder}\\{name_folder}\\'
copy_tree(path_folder, backup_full_path)
it works fine till it get to some specific file and rise the following error:
Traceback (most recent call last):
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\file_util.py", line 48, in _copy_file_contents
buf = fsrc.read(buffer_size)
PermissionError: [Errno 13] Permission denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/UserR/PycharmProjects/my_scripts/main_backup.py", line 28, in <module>
copy_tree(path_folder, backup_full_path)
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\dir_util.py", line 159, in copy_tree
verbose=verbose, dry_run=dry_run))
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\dir_util.py", line 159, in copy_tree
verbose=verbose, dry_run=dry_run))
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\dir_util.py", line 159, in copy_tree
verbose=verbose, dry_run=dry_run))
[Previous line repeated 1 more times]
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\dir_util.py", line 163, in copy_tree
dry_run=dry_run)
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\file_util.py", line 151, in copy_file
_copy_file_contents(src, dst)
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\file_util.py", line 51, in _copy_file_contents
"could not read from '%s': %s" % (src, e.strerror))
distutils.errors.DistutilsFileError: could not read from 'e:\folder_a\0\binlog': Permission denied
Process finished with exit code 1
How can I update the permissions in windows so my script would be able to read and copy the files?

Autocomplete-Python not working, ATOM, Error from jed, grammer 3.9.txt not found

I upgraded my python version from 3.8 to 3.9. I was using autocomplete-Pythonn extension. And an error came in my atom editor. That grammer3.9.txt not found.
Looks like this error originated from Jedi. Please do not report such issues in autocomplete-python issue tracker. Report them directly to Jedi. Turn off outputProviderErrors setting to hide such errors in future. Traceback output:
*Traceback (most recent call last):
File "C:\Users\hp.atom\packages\autocomplete-python\lib\jedi\parser_init_.py", line 56, in load_grammar
return _loaded_grammars[path]
KeyError: 'C:\Users\hp\.atom\packages\autocomplete-python\lib\jedi\parser\grammar3.9.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hp.atom\packages\autocomplete-python\lib\completion.py", line 376, in watch
self._process_request(request)
File "C:\Users\hp.atom\packages\autocomplete-python\lib\completion.py", line 338, in process_request
script = jedi.api.Script(
File "C:\Users\hp.atom\packages\autocomplete-python\lib\jedi\api_init.py", line 126, in init
self.grammar = load_grammar(version='%s.%s' % sys.version_info[:2])
File "C:\Users\hp.atom\packages\autocomplete-python\lib\jedi\parser_init.py", line 58, in load_grammar
return _loaded_grammars.setdefault(path, generate_grammar(path))
File "C:\Users\hp.atom\packages\autocomplete-python\lib\jedi\parser\pgen2\pgen.py", line 393, in generate_grammar
p = ParserGenerator(filename)
File "C:\Users\hp.atom\packages\autocomplete-python\lib\jedi\parser\pgen2\pgen.py", line 18, in init
stream = open(filename)
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\hp\.atom\packages\autocomplete-python\lib\jedi\parser\grammar3.9.txt'
I came up with this error last time. But then I Just renamed the file grammer3.7 to grammer3.8. But I do not think this is the right way to do so.

FileNotFoundError: [Errno 2] No such file or directory: '2MCREF~E.JPG'

I'm trying to open an image that resides at a different location than my script
Code:
import os
from PIL import Image
folder = '/Users/abc'
if not os.listdir(folder):
print('Folder not found')
else:
print('"{}" found'.format(folder))
for file in os.listdir(folder):
print(file)
data = Image.open(file,'r')
print('Done')
Error:
"/Users/abc" found
2MCREF~E.JPG
Traceback (most recent call last):
File "img_to_s3bucket.py", line 25, in <module>
data = Image.open(file,'r')
File "/Users/AjayB/anaconda3/envs/MyDjangoEnv/lib/python3.6/site-packages/PIL/Image.py", line 2770, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '2MCREF~E.JPG'
How to tackle this?
This could be because your working directory and the location of the file are not same.
You could do this by specifying the full file path in the below command:
data = Image.open(file,'r')
you can do this by:
data = Image.open(os.path.join(folder, file),'r'))

Constant error when using ImageMagick with Python

When I did a code to convert PDF files to JPG images, but I have met an issue.Sometimes the .pdf file work well.But sometimes there is an error,the first temp file can't read.I checked the temp folder.When it works well, all the created temp file be deleted successfully. And when the error happens,only the first temp file is deleted. I can't resolve it.Anyone can fix?
code:
from wand.image import Image
with open("C:\software\1234.pdf",'rb') as f:
image_binary = f.read()
f.close()
with Image(blob=image_binary,resolution=400) as img:
Traceback (most recent call last):
File "C:\xxxx\eclipse-workspace\test\123\pdf2jpg.py", line 16, in
with Image(blob=image_binary,resolution=400) as img:
File "C:\xxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\image.py", line 2742, in init
self.read(blob=blob, resolution=resolution)
File "C:\xxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\image.py", line 2822, in read
self.raise_exception()
File "C:\xxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\resource.py", line 222, in raise_exception
raise e
wand.exceptions.CorruptImageError: unable to read image data `C:/xxxx/AppData/Local/Temp/magick-22200zyw89Zpq8IFJ1' # error/pnm.c/ReadPNMImage/1344
Exception ignored in:
Traceback (most recent call last):
File "C:\xxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\resource.py", line 232, in del
File "C:\xxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\image.py", line 2767, in destroy
TypeError: object of type 'NoneType' has no len()

FileExistsError: [Errno 17] File exists: '/root/analytics/venv-nerapi/lib/python3.6/lib-dynload' while creating virtual environment

$virtualenv -p python3.6m ../venv-nerapi
Above command gives following error.
Running virtualenv with interpreter /usr/local/bin/python3.6m
Using base prefix '/usr/local'
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/virtualenv.py", line 352, in copyfile
os.symlink(srcpath, dest)
FileExistsError: [Errno 17] File exists: '/usr/local/lib/python3.6/lib-dynload' -> '/root/analytics/venv-nerapi/lib/python3.6/lib-dynload'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/virtualenv.py", line 2343, in <module>
main()
File "/usr/local/lib/python3.6/site-packages/virtualenv.py", line 712, in main
symlink=options.symlink)
File "/usr/local/lib/python3.6/site-packages/virtualenv.py", line 927, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/usr/local/lib/python3.6/site-packages/virtualenv.py", line 1132, in install_python
copyfile(join(stdlib_dir, fn), join(lib_dir, fn), symlink)
File "/usr/local/lib/python3.6/site-packages/virtualenv.py", line 355, in copyfile
copyfileordir(src, dest, symlink)
File "/usr/local/lib/python3.6/site-packages/virtualenv.py", line 330, in copyfileordir
shutil.copytree(src, dest, symlink)
File "/usr/local/lib/python3.6/shutil.py", line 315, in copytree
os.makedirs(dst)
File "/usr/local/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/root/analytics/venv-nerapi/lib/python3.6/lib-dynload'
I followed following Github issue thread but din't find any luck.
Could any body tell whats went wrong ?
Thanks
Turns out that there was existing venv-nerapi . Deleting existing virtual env and re-creating it worked fine.

Resources