Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File not found error
#1
Hello,

I wrote this code in eclipse / pydev. On running as Python Run it is throwing an error as

FileNotFoundError: [Errno 2] No such file or directory: 'TestEDI.txt'

import os.path
import shutil
from os import path

def main():

    print ("file exist:"+str(path.exists("C:/Users/Desktop/TestEDI.txt")))
       
#Copy a file with new name
newPath = shutil.copy('TestEDI.txt', 'C:/GNS082/Desktop/Test2Jan')
print ("file exist at new destination:"+str(path.exists('C:/Users/Desktop/TestEDI.txt')))
   
if __name__== "__main__":
   main()
Whats wrong with this code as it is working on my python IDLE on local system.

Thanks !
Adi
Reply
#2
can you try putting full path of file and see if that helps, i doubt working directory would have been different when run from IDE causing the issue.


import os
print(os.getcwd()) #check working directory, if file not here, add full directory location for filename
newPath = shutil.copy(r'C:/Users/Desktop/TestEDI.txt', r'C:/GNS082/Desktop/Test2Jan')
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
Reply
#3
It worked.

Thanks Bro!
Reply
#4
i have been getting the errno2 on my raspberry pi and pc using python 3 aswell i was following this tutroial.

https://maker.pro/raspberry-pi/projects/...en-display

can someone help me

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'
Reply
#5
Well, the file doesn't exist in that path. Are you sure that the path is correct?
Reply
#6
Yes the directory does exist and all the WeatherIcons are located in that directory

You can try the tutorial from the link I provided and see if the same error comes for you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Absolute paths in subprocess - file not found kittyticker 4 481 Jan-28-2024, 10:37 PM
Last Post: kittyticker
  file open "file not found error" shanoger 8 1,087 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Module Not Found Error bitoded 4 1,402 Jan-01-2023, 09:08 AM
Last Post: bitoded
  File not found error saisankalpj 10 3,826 Jul-04-2022, 07:57 AM
Last Post: saisankalpj
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,100 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 2,539 Nov-23-2020, 05:15 PM
Last Post: cananb
  Unknown error occurred: Port not found NewBeie 0 1,431 Aug-27-2020, 08:50 PM
Last Post: NewBeie
  uising python zero with IDLE I get an error of 'module not found' Brian123 1 3,890 Apr-24-2019, 09:21 PM
Last Post: Yoriz
  How to fix error code 2 in python, “directory not found”? dav3javu 1 7,028 Apr-03-2019, 04:55 PM
Last Post: Larz60+
  modify line in file if pattern found in list. kttan 1 2,215 Dec-10-2018, 08:45 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020