0

Possible Duplicate:
How do I run a python program in the Command Prompt in Windows 7?

This is a follow-up to this question: Run a python script in windows.

How would I do the equivalent of

`$ ./checksum.py <folder>

in Windows? Note, the checksum.py file starts thus:

#!/usr/bin/env python
Community
  • 1
  • 1
David542
  • 104,438
  • 178
  • 489
  • 842
  • By no means is this an "exact duplicate" of the linked question. This is about running a script in the Windows CLI *without* including the reference to `python` in the command. Answers involving `PATH` are *incorrect.* Windows uses the filename extension to determine what executable to use to run the script in this situation. – kindall Feb 16 '12 at 00:26

4 Answers4

1

For me, it works just to invoke the name of the script directly, e.g. > myscript.py.

recursive
  • 83,943
  • 34
  • 151
  • 241
0

if you have python installed on your system just make sure it's in the global variables. Then you can type in "python " eg "python myscript.py abcd".

If it's not registered at global level you have to 'cd' (ChangeDir) to the location where python is installed, then run a command "python " eg: "C:\Programs\Python>python C:\Users\User1\Desktop\MyScript.py abcd" where "C:\Programs\Python" is the current working directory.

If you want to run linux programs and commands on windows you can try MinGW or CygWin.

0

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.

piersadrian
  • 1,653
  • 12
  • 12
0

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.

kindall
  • 178,883
  • 35
  • 278
  • 309