i have been getting the errno2 on my raspberry pi aswell i was following this tutroial.
https://maker.pro/raspberry-pi/projects/...en-display
can someone help me
Error:
Traceback (most recent call last): File "C:\Users\user\Documents\hi.py", line 305, in <module> window.resize_icons() File "C:\Users\user\Documents\hi.py", line 284, in resize_icons fp = open(original_path) FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\WeatherIconsclear-day.png'
First question: does the file exist?
Yes the files exist in the directory. You can also check the link I posted to the tutorial and see if you are getting the same error.
Has anybody managed to use the code in the tutorial and find a fix.
saqib1066 Wrote:FileNotFoundError: [Errno 2] No such file or directory:
I have never seen Python lie about this,so what reported is the problem..
To show a test with the part that give error.
First test:
import os
directory = r'C:/code/img/' # See that i use / other way
for file in os.listdir(directory):
print(file)
Output:
foo.html
img.py
test.png
WeatherIconsclear-day.png
Works see that files are there.
Add second part and
print()
work fine as debug tool,can also add
repr
.
import os
directory = r'C:/code/img/' # See that i use / other way
for file in os.listdir(directory):
#print(file)
if file.endswith('.jpeg') or file.endswith('.png'): # expand depending on what file types your icons are
original_path = directory + file
# open images so they can be resized
print(repr(original_path)) # Use print to see that path is correct,repr show all
fp = open(original_path)
Output:
'C:/code/img/test.png'
'C:/code/img/WeatherIconsclear-day.png'
No error so the files get open bye
open()
.
The part that easy can go wrong is
original_path = directory + file
like missing a
/
or
\\
(never single
\
in path) in the concatenate.
Sorry I'm new to programming so what do I need to add to the code to fix it.
I have tried listdir(directory)
Output
Clear-day.png
Clesr-night.png
Cloudy.png
Fog.png
Partly-cloudy-day.png
Partly-cloudy-night.png
Rain.png
Sleet.png
Snow.png
Wind.pnd
So it is showing all the files and working
I have tried the print(repr(original_path))
Output
'C:Users\\user\\Documents\\Raspberrypi-Noticeboard-master\\WeatherIconsclear-days.png'
So path seems correct but still the same errno 2
Do exactly what i have showed,just with your folder.
So first part for you based on error message should be.
import os
directory = 'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\'
for file in os.listdir(directory):
print(file)
Also you shall
run this code and see if
WeatherIconsclear-day.png
is in the output.
If you see that file add second part,just the same as i have posted.
The path
C:\\Users\\user\\Documents
is a little strange.
For Window the default path to Documents is
C:\Users\<user name>\Documents
.
So eg if i should navigate in
cmd
to Documents it look like this.
C:\>cd Users
C:\Users>cd tom # My user name
C:\Users\Tom>cd Documents
C:\Users\Tom\Documents>
I have tried listdir(directory)
Output
Clear-day.png
Clesr-night.png
Cloudy.png
Fog.png
Partly-cloudy-day.png
Partly-cloudy-night.png
Rain.png
Sleet.png
Snow.png
Wind.pnd
So it is showing all the files and working
I have tried the print(repr(original_path))
Output
'C:Users\\user\\Documents\\Raspberrypi-Noticeboard-master\\WeatherIconsclear-day.png'
So path seems correct but still the same errno 2
The WeatherIcons is a folder and inside there is
Clear-day.png
Clesr-night.png
Cloudy.png
Fog.png
Partly-cloudy-day.png
Partly-cloudy-night.png
Rain.png
Sleet.png
Snow.png
Wind.png
import os
directory = r'C:/Users/user/Documents/RaspberryPi-Noticeboard-master/WeatherIcons'
for file in os.listdir(directory):
print(file)
output
clear-day.png
clear-night.png
cloudy.png
fog.png
forecast
partly-cloudy-day.png
partly-cloudy-night.png
rain.png
sleet.png
snow.png
todays
wind.png
>>>
The missing \\ that's my mistake on this message I accidentally missed typing them
output
'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\WeatherIconsclear-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)
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\WeatherIconsclear-day.png'
>>>