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?
-
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– Terry Jan Reedy2020-06-18 15:52:12 +00:00Commented Jun 18, 2020 at 15:52
Add a comment
|
2 Answers
since I cant comment yet:
go to the command line and open the file location directory and type: python filename.py
2 Comments
Sachin Prabhu
are you sure you do not have a syntax error in the code itself?
Shivansh Potdar
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
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.
7 Comments
H Gaming
I've tried both of these, the .bat file dosnt run and the filename.py comes up as syntax error
Ransaka Ravihara
Have you set python in your path variable
H Gaming
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
Ransaka Ravihara
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
H Gaming
python: can't open file 'file name': [Errno 2] No such file or directory
|