Run Python Script From Another Directory
I feel a little foolish that I don't know this, but I tried to do it today and was surprised when it didn't work.... I have a directory C:\test with a demo script, lets call it dem
Solution 1:
The PATH is only used to search for commands. A first way is that a Python script can be used directly as a command and in that case the PATH will be used: just use demo.py
instead of python demo.py
.
It will rely on OS specific ways. On Windows, file type (given by the extension - here .py) can be given default application to process them, while on Unix-like, the first line of a script can declare the program that will process it.
Alternatively, python allows to launch a module that will be searched in the PYTHONPATH (not PATH) by using python -m module
or for Windows py -m module
.
Post a Comment for "Run Python Script From Another Directory"