I'm a first-year CS student, and I hit a snag while trying to run my Python file. I followed my professor's quick instructions, but now I'm stuck! I created a Python file using Notepad++, and when I try to run it in Command Prompt with the command 'python filename.py', I get an error saying it can't find the file. The full error is: "python: can't open file 'C:Users*myusername*hello.py': [Errno 2] No such file or directory". Can anyone guide me through what I'm doing wrong? Please be kind as I'm new to all this!
3 Answers
Make sure you're using the full path to your file. If your Python file is on the Desktop, you need to either navigate to that folder in Command Prompt using the 'cd' command or provide the full path directly. Like, if your file is called hello.py, you’d do:
python C:Users*yourusername*Desktophello.py
This way, Python knows exactly where to look!
If all else fails, check to see if you've spelled the file name correctly, and remember that file paths on Windows use backslashes! It can be easy to miss those little details, especially when you’re figuring things out for the first time.
True! Typos can definitely be tricky. And if it’s on the Desktop, remember that it should match exactly what you named the file.
Oh, and just to clarify, when you’re in Command Prompt, make sure you're in the right folder that contains your .py file. You can use the 'dir' command to list files in the current directory to see if it’s there. If not, you need to navigate to the right folder first!
Got it! I’ll check my current directory and navigate using 'cd'. Thanks for the tip!

Yeah, and don't forget to check if you're actually in the right directory when you run the command. You can type 'cd Desktop' to go there first.