Python Forum
FileNotFoundError: [Errno 2] No such file or directory - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: FileNotFoundError: [Errno 2] No such file or directory (/thread-25015.html)

Pages: 1 2 3


RE: FileNotFoundError: [Errno 2] No such file or directory - snippsat - Mar-16-2020

(Mar-16-2020, 12:25 AM)saqib1066 Wrote: The WeatherIcons is a folder and inside there is
The you are missing two \\ at end in the path.
directory = 'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\WeatherIcons\\'


RE: FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-16-2020

i get this error
Error:
'C:/Users/user/Documents/RaspberryPi-Noticeboard-master/WeatherIcons/clear-day.png' Traceback (most recent call last): File "C:\Users\user\Documents\hi.py", line 306, in <module> window.resize_icons() File "C:\Users\user\Documents\hi.py", line 286, in resize_icons img = PIL.Image.open(fp) File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\Image.py", line 2818, in open prefix = fp.read(16) File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 146: character maps to <undefined> >>>
if i use directory = r'C:\Users\user\Documents\RaspberryPi-Noticeboard-master\WeatherIcons\'
it gives me error EOL while scanning string literal


RE: FileNotFoundError: [Errno 2] No such file or directory - snippsat - Mar-16-2020

Use what i posted.
directory = 'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\WeatherIcons\\'



RE: FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-16-2020

i used it and gave me this error
Error:
'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\WeatherIcons\\clear-day.png' Traceback (most recent call last): File "C:\Users\user\Documents\hi.py", line 306, in <module> window.resize_icons() File "C:\Users\user\Documents\hi.py", line 286, in resize_icons img = PIL.Image.open(fp) File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\Image.py", line 2818, in open prefix = fp.read(16) File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 146: character maps to <undefined> >>>



RE: FileNotFoundError: [Errno 2] No such file or directory - snippsat - Mar-16-2020

Add this in open().
fp = open(original_path, encoding='utf-8')



RE: FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-16-2020

this error now

'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\WeatherIcons\\clear-day.png'
Traceback (most recent call last):
File "C:\Users\user\Documents\hi.py", line 306, in <module>
window.resize_icons()
File "C:\Users\user\Documents\hi.py", line 286, in resize_icons
img = PIL.Image.open(fp)
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\Image.py", line 2818, in open
prefix = fp.read(16)
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
>>>


RE: FileNotFoundError: [Errno 2] No such file or directory - snippsat - Mar-16-2020

Now is your fist error gone,if i think of it so may pillow need binary mode.
Try:
fp = open(original_path, 'rb')



RE: FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-16-2020

ive added

fp = open(original_path, 'rb', encoding='utf-8')

error
'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\WeatherIcons\\clear-day.png'
Traceback (most recent call last):
File "C:\Users\user\Documents\hi.py", line 306, in <module>
window.resize_icons()
File "C:\Users\user\Documents\hi.py", line 285, in resize_icons
fp = open(original_path, 'rb', encoding='utf-8')
ValueError: binary mode doesn't take an encoding argument
>>>

and tried this

fp = open(original_path, 'rb')


error

'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\WeatherIcons\\clear-day.png'
Traceback (most recent call last):
File "C:\Users\user\Documents\hi.py", line 306, in <module>
window.resize_icons()
File "C:\Users\user\Documents\hi.py", line 293, in resize_icons
img = PIL.Image.open(fp)
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\Image.py", line 2818, in open
prefix = fp.read(16)
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 146: character maps to <undefined>
>>>

Here's the link to the code it's all at the bottom of the page and also the folder with the images is there too.maybe you can fix it
https://maker.pro/raspberry-pi/projects/raspberry-pi-noticeboard-using-7-touchscreen-display


RE: FileNotFoundError: [Errno 2] No such file or directory - snippsat - Mar-16-2020

Comment out or delete this line.
#fp = open(original_path)
Make sure that pillow is the newest.
pip install pillow --upgrade 
Now i test code with one image,as the loop dos just same with more images.
C:\code\img
λ ptpython
>>> import PIL.Image

>>> # Now open directly in pillow,do not need a file object
>>> img = PIL.Image.open('day.png')

>>> # Set 100 x 100 which is set first in code and remove "self" for this test.
>>> width = 100
>>> height = 100
>>> resizedImage = img.resize((width, height), PIL.Image.ANTIALIAS) # Test what's done in code

>>> # Show image is now resized to 100 x 100
>>> resizedImage.show()
Do of course work the same with a path when not in same folder as image,as you use in the code.
>>> original_path = 'C:\\code\\img\\day.png'
>>> img = PIL.Image.open(original_path)
>>> img.show()



RE: FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-16-2020

I'm a little confused can you go to the link and copy the code at the end and see if you can make it work it would be a great help to me.

https://maker.pro/raspberry-pi/projects/raspberry-pi-noticeboard-using-7-touchscreen-display