I can't run python scripts just by typing python nameofthescript.py
on Windows 10 cmd
. The only way to make it work is by typing python
followed by space and C:\script\directory\nameofthefile.py
.
I just would like to use a quick way to run python scripts. Already tried to type py
instead of python.
I've already added the directory to the PATH
environment variable. Have not been able to find the answer online. If more information is needed to solve the problem, I can try to provide it.
dpath
is the equivalent to path
for data files. Type dpath /?
note it was once called append
and the help hasn't been updated.
That answers your question as you've asked.
Perhaps you should have asked how do I just type my script name ?
So
associate .py
with the python interpreter.
Use commands ftype
and assoc
ftype PythonScript=c:\pathtofolder\python.exe %*
assoc .py=PythonScript
Then add your SCRIPT path to the path command
Setx path "%path%;C:\MyPythonScriptFolder"
Set path=%path%;C:\MyPythonScriptFolder"
Then tell windows command prompt to assume.py files are executable so it will search the path for it.
Set pathext=%pathext%;.py
Your command prompt should be in the folder with the file in it. Eg, if you cd C:\script\directory
then you could python nameofthescript.py
Check if your file has permission to be executed. I'm not familiar with Windows, but on Linux it's chmod +x name_of_file.py
, or with sudo, if you need root privileges. Also, check your python default version, because in most cases python calls python2.7 and not python3...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.