Run A Python Script From The Prompt In Windows
Solution 1:
For me, it works just to invoke the name of the script directly, e.g. > myscript.py
.
Solution 2:
One potential solution to this problem, while possibly overkill, is to install Cygwin and use its environment to run the script. Of course you can just call the python
command from your Windows command line (as long as it's in your PATH, as specified in autoexec.bat
) followed by ./checksum.py [folder]
, but if you're coming from a *nix/OS X environment, you may find Cygwin makes your life simpler. Either way.
Solution 3:
Make sure the filename extension .py
is associated with the appropriate python.exe
. Similarly, .pyw
should be associated with pythonw.exe
(this is a version of the Python interpreter that doesn't show a terminal window, suitable for use with Python GUI scripts).
The Python for Windows installer does this, so you usually won't have to mess with it unless you have multiple Python installs on your machine. If you do need to change the association, this can be done by right-clicking a .py
file, choosing Properties, and clicking the Change button next to "Opens with."
Windows ignores the shebang line, so there is no way (short of Cygwin) to have different scripts use different versions of Python by changing the shebang. You could use a different extension (e.g. .py3
for Python 3 scripts) and associate that with C:\Python31\python.exe
-- but that will break the script's ability to be imported as a module (Python expects the .py
extension), so use it carefully. Better practice is probably to just specify the desired python.exe
directly on the command line.
Post a Comment for "Run A Python Script From The Prompt In Windows"