I am getting this error: `C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\python.exe: can’t open file ‘C:\Users\Anthony.DESKTOP-ES5HL78\04_02.py’: [Errno 2] No such file or directory’
I am sure my directory is correct. What am I missing?
As the error plainly states, you are presumably missing the Python file
04_02.py in your user home directory that you attempted to run. Either you misspelled the name/path of the file when you invoked Python, or the file is not located where you think it is.
I’m not sure what else you expect us to tell you, sorry, given that was the only information you gave us.
@CAM-Gerlach I get the same error. I am doing a Python Course and I need to run it from the command line. But I get this error.
C:\Users\Legion 5\AppData\Local\Programs\Python\Python311\python.exe: can’t open file ‘c:\users\legion5\mypythonscripts\hello.py’: [Errno 2] No such file or directory
Even though I have the files right where it should be. I m a beginner, sorry if I don’t provide enough information for you, please let me know what else should I let you know.
It’s not where you think it is.
You’re saying that it’s:
but it’s really:
Wait, I m more confused now than before. I don’t think I get get what you re saying. I just copy paste the error here.
But if I look closer, i see that the command is looking in another folder. From what I see above the PC is looking in C:\Users\Legion 5\AppData\Local\Programs\Python\Python311 instead of C:\Users\Legion 5\MyPythonScripts.
Is this what you re saying?
It can’t find
contains a space and:
‘legion5’ (no space) is not the same as ‘legion 5’ (with space).
Fun shortcut in Explorer: if you click in the address bar (where it says “> This PC > Local Disk(C:) > etc”) and type
cmd and press Enter, it will open a command prompt already navigated to that directory, so you don’t have to type a series of
cd _ commands.
Ok, thanks I got that. But the error is the following C:\Users\Legion 5\AppData\Local\Programs\Python\Python311\python.exe: can’t open file ‘c:\users\legion5\mypythonscripts\hello.py’: [Errno 2] No such file or directory .From what I can see, it doest stop in “legion 5”(where the folder is) its gooing through in 'appdata\local…" and so on. Why is that.
Please also note that i tried with spaces, without spaces, with quotation mark and without…
Maybe i messed something up withput even knowing?
You have Python is installed in
C:\Users\Legion 5\AppData\Local\Programs\Python\Python311. That’s because you have it installed for just you (your “Legion 5” user account) and not for “all users”, i.e. not for other user accounts.
You’re asking Python run
c:\users\legion5\mypythonscripts\hello.py, but that’s not the correct path. The correct path is, presumably,
When you created the user account you called it “Legion 5” (with a space), but you’re omitting the space when giving the path. Hence, Python can’t find the file.
On Windows it’s recommended to use the “Python Launcher”, so to run the file:
py "c:\users\legion 5\mypythonscripts\hello.py"