Reputation: 4007
I have a python script that i want to run from the command line but unsure how to run it. Thanks :)
Upvotes: 1
Views: 8838
Reputation: 86344
See Basic Hints for Windows Command Line Programming.
If your python installation directory is included in %PATH%
-
C:\> python myscript.py
If you know the installation path:
C:\> C:\python26\python myscript.py
And, you can insert a hashbang
in the 1st line of the script:
#! C:\python26\python
and it will run by typing just the script name. This is the content of p.py
:
#!C:\python26\python
import sys
print sys.path
And calling it directly from a cmd.exe
window:
C:\>p.py
['C:\\WINDOWS\\system32\\python26.zip', 'C:\\Python26\\DLLs',
'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win',
'C:\\Python26', 'C:\\Python26\\lib\\site-packages',
'C:\\Python26\\lib\\site-packages\\win32', 'C:\\Python26\\lib]
Upvotes: 3
Reputation: 2830
You might find it useful to include a .bat file which calls the .py script. Then all you need to do is to type the name of your script to run it.
Try something like: python %~dp0\%~n0.py %*
(From http://wiki.tcl.tk/2455)
Upvotes: 1
Reputation: 88727
on command line use
python "path to script.py"
if python is not in PATH list you can add it to PATH in environment variables or directly use path to python.exe e.g.
c:\python25\python.exe myscript.py
Upvotes: 0
Reputation: 80712
If your script is foo.py, you can simply do
C:\Python25\python.exe foo.py
Assuming you have python 2.5 installed in the default location. Alternatively, you can add C:\Python25 to your %PATH%, so that:
python foo.py
will work. But be aware that changing %PATH% may affect applications (that's why it is not done by the python installer by default).
Upvotes: 2