[Errno2] when running No such file or directory appears.

Asked 2 years ago, Updated 2 years ago, 309 views

I have been using python for some complicated calculations (PC: Mac-OS, code write: Atom, calculation run: terminal).

Due to business reasons, I bought a new PC and tried to reflect the calculations I made on my previous PC in the following way, but an error was displayed saying "No such file or directory".

Username@MacBook-Air~%ls/Users/Username/Desktop/Research/python_lesson
script-2.py script.py

Username @MacBook-Air to %python script-2.py                               
/Users/Username/.pyenv/versions/3.6.5/bin/python:can't open file'script-2.py': [Errno2] No such file or directory

As you can see above, since you have verified that the file you want to reflect the results in the specified folder, it is possible that the path may not work due to the replacement of the PC.

One thing I'm concerned about is that when I tried to open the above file, python version said 3.6.5 but when I opened the script-2.py file itself, it said 3.8.2, so I think it might be related to the change of version.

I'm sorry for the above, but I'd appreciate it if someone could reply.

Thank you for your cooperation.

python macos

2022-09-30 22:03

1 Answers

From the prompt, the current directory appears to be the home directory (~), but the program you are trying to run is stored in a different directory, so you get the error "File Not Found".

Navigate to the file location and run it, or specify the file as an absolute path.

Go to the save location and run:

$cd/Users/Username/Desktop/Research Related/python_lesson
$ python script-2.py

Run with absolute path:

$python/Users/Username/Desktop/Research/python_lesson/script-2.py


2022-09-30 22:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.