Adding Python to the path in Windows

Duncan Booth duncan.booth at invalid.invalid
Thu Jun 21 11:10:08 EDT 2007


kyle at thenortheastgroup.com wrote:

> I have many users using two different versions of python, 2.4 and
> 2.5.  I am running Python scripts on their computers programmatically,
> but I can't run it with the full path because they have different
> versions installed.  I need to run it like 'python {script name}'.  So
> I need to add Python to the path.  How do I do this permanently
> without going to each computer and setting it through the GUI?  I
> tried creating a Windows batch script using setx, but the user had to
> be an administrator.
> 
> Or is there any other way I can run whatever version of Python happens
> to be installed with a single command?  Anyone have any ideas?  Such a
> simple issue, there must be a simple solution. (of course, this is
> Windows).
> 
Assuming they have Python installed normally there will be file 
associations set up for .py and .pyw, so all you need to do to type in 
the script name: Python itself does not need to be in the path.
N.B. You do need to include the .py extension unless you can arrange to 
edit the PATHEXT environment variable.

e.g.

C:\Temp>type t.py
import sys
print sys.version

C:\Temp>t.py
2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)]

C:\Temp>assoc .py
.py=Python.File

C:\Temp>ftype Python.File
Python.File="C:\Python25\python.exe" "%1" %*




More information about the Python-list mailing list