The problem I can see here is most likely caused because you have whitespace in the script's name.
So the command line parses the name of the script up to the first word and thinks it is just Hello.
Try those two following things:
python "Hello World.py"
or
python Hello\ World.py
The quotes should "tell" the cmd that it is a single argument hence all of it is the name. Even if that doesn't work, the backslash just escapes the whitespace and that should work.
And another thing you could do is just rename the script to something like Hello_World.py - without any special symbols or whitespace.
can't open file 'main.py': [Errno 2] No such file or directory
python.exe: can't open file 'generate_fingerprint.py': [Errno 2] No such file or directory Press any key to continue . . .
Directory not found
android - Command Error: python.exe can't open file - Stack Overflow
The problem I can see here is most likely caused because you have whitespace in the script's name.
So the command line parses the name of the script up to the first word and thinks it is just Hello.
Try those two following things:
python "Hello World.py"
or
python Hello\ World.py
The quotes should "tell" the cmd that it is a single argument hence all of it is the name. Even if that doesn't work, the backslash just escapes the whitespace and that should work.
And another thing you could do is just rename the script to something like Hello_World.py - without any special symbols or whitespace.
I found a solution to my problem. I found it here: https://docs.python-guide.org/starting/install3/win/#install3-windows
After I followed this guide installing chocolatey and then others it fixed my problem.
Hello, RonanH_86
Welcome to the Microsoft Community.
Hello, thank you for your feedback here, it looks like you are having problems opening Python files.
To help you better, can you ask if the Python file you are opening is a source file or a copy sent from another source etc., in general the flashing popup window could be a file exception. I will provide you some troubleshooting suggestions for you first:
- Make sure Python is installed
First, make sure Python is installed on your computer.
Press Win + R, type cmd, and press Enter to open a command prompt.
Enter the following command at the command prompt:
python --version
If a version message like Python 3.x.x is returned, then Python is installed correctly. If not, go to python.org to download and install Python.
- Running Python from the Command Prompt
Running a Python file from the command prompt allows you to see possible error messages without having the window close quickly.
Open a command prompt:
Press Win + R, type cmd, and press Enter to open the command prompt.
Navigate to the directory where the Python files are located:
Use the cd command to enter the folder where the Python files are stored. For example, if the files are in the C:\Users\YourUsername\Downloads folder, type:
cd C:\Users\YourUsername\Downloads
Then press Enter, and the command prompt will display the current directory.
Run the Python file:
Enter the following command to run the Python file, assuming your file name is yourfile.py:
python yourfile.py
After running, if the script has errors, they will be displayed in the command prompt window and you can see the detailed error message.
- Adding a pause statement
If you want the window not to close automatically even if the script has no errors, you can add a pause statement to the end of the Python script. That way, when the program finishes executing, you'll be prompted to press the key to continue.
Add the following code to the end of your Python file:
input(“Press Enter to exit...”)
This line of code will cause the Python program to pause at the end and wait for you to press Enter before closing the window.
- File Association Settings
Sometimes the file associations on Windows systems can be incorrect, causing the .py file to close automatically when you double-click on it. You can fix the file association settings:
Right-click on the .py file and select Open as > Select another application.
In the pop-up window, select Python (if Python is not shown, click More Applications to select Python).
Check Always use this application to open .py files, and then click OK.
- Check for other errors
If you encounter an error when running from the command prompt, double-check the error message. There may be something wrong with the file, such as a missing library or a syntax error.
Best regards
Bobhe | Microsoft Community Support Specialist
Hi Bobhe,
Thank you for your reply.
Regarding your question, I don't know if it is a source file or copy sent from another source, and I don't know how to find that out.
Regarding the troubleshooting steps:
- I get the message "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases".
- I get the message "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases."
However, I have confirmed that I have correctly downloaded and installed Python 3.13.1-amd64.
I have not yet proceeded to the subsequent steps.
Thank you,
Ronan
When you run a script from the prompt you need to use the whole path to the file (as you did when running python C:\Python37\projects\file.py) or you need to first move to the directory containing the file and then run, otherwise you rise the error you got (cause there's no file with such name in your current directory). You can move to another directory using the command cd. So what you could do if you don't want to type the path every time you run the code is:
cd C:\Python37\projects
python file.py
Open your script in another code editor like VS and check extension. It usually keeps txt behind py and that is why you get an error. Or in Options, if you use Windows, Hide extensions for known file types.
Python cannot access the files in the subdirectory unless a path to it provided. You can access files in any directory by providing the path. python C:\Python27\Projects\hello.py
I resolved this problem by navigating to C:\Python27\Scripts folder and then run file.py file instead of C:\Python27 folder