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) |
FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-15-2020 i have been getting the errno2 on my raspberry pi aswell i was following this tutroial. https://maker.pro/raspberry-pi/projects/raspberry-pi-noticeboard-using-7-touchscreen-display can someone help me
RE: FileNotFoundError: [Errno 2] No such file or directory - ibreeden - Mar-15-2020 First question: does the file exist? RE: FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-15-2020 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. RE: FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-15-2020 Has anybody managed to use the code in the tutorial and find a fix. RE: FileNotFoundError: [Errno 2] No such file or directory - snippsat - Mar-15-2020 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) 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) 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.
RE: FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-16-2020 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 RE: FileNotFoundError: [Errno 2] No such file or directory - snippsat - Mar-16-2020 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> RE: FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-16-2020 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 RE: FileNotFoundError: [Errno 2] No such file or directory - snippsat - Mar-16-2020 (Mar-16-2020, 12:06 AM)saqib1066 Wrote: I have tried listdir(directory)I do not see WeatherIconsclear-days.png there.(Mar-16-2020, 12:06 AM)saqib1066 Wrote: I have tried the print(repr(original_path))Look closer two missing \\ ,shall bee C:\\Users\\user...
RE: FileNotFoundError: [Errno 2] No such file or directory - saqib1066 - Mar-16-2020 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' >>> |