2

Possible Duplicate:
How to make python scripts executable on Windows?
Set up Python on Windows to not type python in cmd

I have a python script under windows. Each time, I need to run using python *.py.

Can I run just as *.py without specify python?

Community
  • 1
  • 1
Adam Lee
  • 24,710
  • 51
  • 156
  • 236

3 Answers3

3

Do you want to run it from the command line or the desktop?

If you set the file association for .py files (this is usually done during the install) you should be able to just double-click on the .py file on the desktop to get it to run.

I don't know of a way to avoid typing python with the command line (and this if it's on the PATH already, otherwise one would have to specify the whole path to the python executable).

It would be nice if we could do something similar like under Linux/Unix with #/usr/bin/env python directive in the script, but I don't think this exists for Windows unfortunately.

You didn't specify what version of Windows you are running, but in case you are interested in assigning/changing file associations, here are Microsoft's instructions on doing that with XP. Very similar with other versions of Windows .. googling will bring up a bunch of hits for how to change file associations.

Levon
  • 138,105
  • 33
  • 200
  • 191
1

I can only refer from the Python doc's: http://docs.python.org/using/windows.html#executing-scripts

Jon Clements
  • 138,671
  • 33
  • 247
  • 280
0

If you're looking to run it automatically from Windows, you could compile the code with py2exe, or you could write a batch file that ran the Python file in question.

Steven Matthews
  • 9,705
  • 45
  • 126
  • 232