faqts : Computers : Programming : Languages : Python : Installation and Configuration : Windows

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

21 of 28 people (75%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I run my Python programs in Windows?
How can I setup Python file extensions on Windows?

Mar 1st, 2000 22:11
Nathan Wallace, Tom Funk, Fredrik Lundh, David C. Ullrich


If you're running under Win32, you could download and install the Win32 
Extensions:

  http://www.python.org/download/download_windows.html

The installer will add the necessary registry entries to allow you to
run a .py or .pyw file from a command line or from within Windows
Explorer.

Also, most IDE's (including IDLE, PythonWin, emacs, etc) have commands
that run your Python program and displays the output.

Otherwise, if you're using Windows with any non-Python aware editor,
fire up a command window (aka MS-DOS prompt) and run the script from
there.  e.g:

    c:\mydir> python myscript.py

If you want to add the file associations by hand it's not hard to make
Windows understand what you want to do.  Like you can make a file py.reg
that looks like this:

REGEDIT4

[HKEY_CLASSES_ROOT\.py]
@="DUPythonFile"

[HKEY_CLASSES_ROOT\DUPythonFile]
@="DUPythonFile"

[HKEY_CLASSES_ROOT\DUPythonFile\DefaultIcon]
@="D:\\Python\\Py.ico"

[HKEY_CLASSES_ROOT\DUPythonFile\shell]
@="Edit"

[HKEY_CLASSES_ROOT\DUPythonFile\shell\Edit]

[HKEY_CLASSES_ROOT\DUPythonFile\shell\Edit\command]
@="C:\\windows\\notepad.exe %1"

[HKEY_CLASSES_ROOT\DUPythonFile\shell\Run(DOS)]

[HKEY_CLASSES_ROOT\DUPythonFile\shell\Run(DOS)\command]
@="d:\\python\\py.bat %1"

[HKEY_CLASSES_ROOT\DUPythonFile\shell\Initialize Interpreter]

[HKEY_CLASSES_ROOT\DUPythonFile\shell\Initialize Interpreter\command]
@="d:\\python\\python.exe -i %1"

[HKEY_CLASSES_ROOT\DUPythonFile\shell\PyWin(Edit)]

[HKEY_CLASSES_ROOT\DUPythonFile\shell\PyWin(Edit)\command]
@="d:\\Python\\Pythonwin\\pythonwin.exe /edit %1"

[HKEY_CLASSES_ROOT\DUPythonFile\shell\PyWin(Run)]

[HKEY_CLASSES_ROOT\DUPythonFile\shell\PyWin(Run)\command]
@="d:\\Python\\Pythonwin\\pythonwin.exe /run %1"

The REGEDIT4 should be the first line of the file. If you execute that
file then *.py files will have associations just like on my machine here
- if you edit the path names, etc then you get what you want.

And you save the py.reg file, so when installing something changes the
associations you re-merge the py.reg file and they're back the way you
want. Very handy for fixing things when some new program thinks you want
it to take over every file extension it can think of.