Adding Python to the path in Windows

Larry Bates larry.bates at websafe.com
Thu Jun 21 17:53:07 CEST 2007


kyosohma at gmail.com wrote:
> On Jun 21, 10:10 am, Duncan Booth <duncan.bo... at invalid.invalid>
> wrote:
>> k... 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" %*
> 
> If your users aren't programmers, then why not just run Python over
> the network? That's what we do at my place of employment. The only
> machines that have Python actually installed are development machines.
> 
> Mike
> 
Another solution is to use py2exe to convert your python program into an .exe
file that you can distribute.  Then they require no Python installation at all.
 I use py2exe and Inno Installer to do just that and it works great.

-Larry



More information about the Python-list mailing list