So I've made a script/code in python idle and want to run it on python.exe but whenever I do this the you can see the python window pop up briefly for a second before closing, and I want to run my code using python instead of idle, how can I do this?
Asked
Active
Viewed 348 times
1
-
What OS? What does 'do this' consist of. What does your program do? It is possible that you have already done what you want to do -- successfully run with python.exe. Why do you think you failed? – Terry Jan Reedy Jun 18 '20 at 15:52
2 Answers
1
since I cant comment yet:
go to the command line and open the file location directory and type: python filename.py

Shivansh Potdar
- 1,146
- 6
- 16
-
-
This is the default option for doing this. Are you opening the file in the correct directory ? E.g.: C:\Users\Docs\Folderl\>python nameoffile.py – Shivansh Potdar Jun 18 '20 at 06:12
0
This can be done using two methods.
The first one is using cmd.
Such as YOUR_WORKING_DIR>python filename.py
Another method is to create .bat
(batch) file that executes your particular python code.
Let us assume you want to run my_python_file.py
using a batch file. relevant script similar to this,
ECHO ON
python my_python_file.py
PAUSE
Save this file as .bat
extension and just double click it!
Incase the above method didn't work for you, Please refer to this answer.

Ransaka Ravihara
- 1,786
- 1
- 13
- 30
-
I've tried both of these, the .bat file dosnt run and the filename.py comes up as syntax error – H Gaming Jun 18 '20 at 05:03
-
-
That's the problem when I try set python as a path variable or try open it already in the python command line it treats it as either not defined, not a command of a syntax error – H Gaming Jun 18 '20 at 05:06
-
Open cmd and type python and press enter. If it says "Python is not recognized as an internal or external command," then follow these steps.[follow this url](https://geek-university.com/python/add-python-to-the-windows-path/) – Ransaka Ravihara Jun 18 '20 at 05:10
-
python: can't open file 'file name': [Errno 2] No such file or directory – H Gaming Jun 18 '20 at 06:52
-
Ahh..try following. navigate to your working directory(the place where your python file located) using `cd` command. then type `python yourfilename.py` **NOTE**: `youfilename` should be replaced with your actual filename. – Ransaka Ravihara Jun 18 '20 at 06:55
-
The system cannot find the path Specified and if I put the whole path it says filename, directory name of volume label syntax is incorrect – H Gaming Jun 18 '20 at 06:59