Adding Python to the path in Windows

K

kyle

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).

Thanks for any help.
 
D

Duncan Booth

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" %*
 
K

kyosohma

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
 
K

kyle

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" %*

Wow, I knew there must be a simple solution, but I didn't know it was
that simple. I feel sort of dumb now! But thanks a lot, that saved
me a lot of work.
 
K

kyle

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

Mike,

I place the scripts on the server, but hadn't thought of placing an
entire Python installation on the server. I just tried it and it
seems to work. It shouldn't cause any problems? That might actually
work out really well too. Thanks for the suggestion.
 
K

kyosohma

Mike,

I place the scripts on the server, but hadn't thought of placing an
entire Python installation on the server. I just tried it and it
seems to work. It shouldn't cause any problems? That might actually
work out really well too. Thanks for the suggestion.

We've been running python scripts over the network for more than a
year. The only issues I can think of is that at first it didn't always
find that weird Python dll file, but once we got that on the server,
that problem went away too.

Mike
 
K

kyosohma

We've been running python scripts over the network for more than a
year. The only issues I can think of is that at first it didn't always
find that weird Python dll file, but once we got that on the server,
that problem went away too.

Mike

I should probably mention that if you have some complicated GUI's,
they will probably load slowly over the network. And I did notice that
scripts using WMI and pyWin32 modules can be slower than they ought to
be. Just something to keep in mind if you have a slow connection. We
have a T1 out to a remote location and it's caused some minor issues
using anything of that nature.

Mike
 
L

Larry Bates

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
 
K

kyle

I should probably mention that if you have some complicated GUI's,
they will probably load slowly over the network. And I did notice that
scripts using WMI and pyWin32 modules can be slower than they ought to
be. Just something to keep in mind if you have a slow connection. We
have a T1 out to a remote location and it's caused some minor issues
using anything of that nature.

Mike

I will probably do this then, because Duncan's solution does not seem
to be working for me. If I run a Python script directly from a
command line, it works fine just like he said. But I am using the
Shell() command in Visual Basic 2005 to run the Python script, and it
doesn't seem to be working. I am getting an error, "File not found".
Not sure what the difference would be. But your solution should work.
 
K

kyle

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

Yeah, I didn't even think of that. The server install of Python seems
like the best option for my situation though. Thanks for all the
great suggestions.
 
Y

Yves Pouplard

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" %*

Then you run some script on the considered pc with the "psexec"
command of the pstools" (look at www.sysinternals.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,113
Latest member
KetoBurn
Top