Switching between Python releases under Windows

Thomas L. Shinnick tshinnic at io.com
Tue Mar 8 12:42:15 EST 2011


At 10:03 AM 3/8/2011, Tim Golden wrote:
>On 08/03/2011 15:58, Tim Golden wrote:
>>On 08/03/2011 14:55, Edward Diener wrote:
>>>I have multiple versions of Python installed under Vista. Is there any
>>>easy way of switching between them so that invoking python and file
>>>associations for Python extensions files work automatically ?
>>
>>Well, the answer depends a bit on how au fait you are with fiddling
>>with env vars etc....
>
>But essentially involves:
>
>* Adding c:\pythonxy and c:\pythonxy\script to PATH
>
>* assoc .py=python.file [probably already done]
>
>* python.file="C:\Pythonxy\python.exe" "%1" %*

More of the answer...

There are perhaps two different things you are asking for.  One is 
easy, one is icky.

If you want to just run the different versions from command line, 
that is just playing with the PATH environment variable.  I start a 
new command window for each version I'm needing and run a canned .bat 
for that version, such as this:
     C:\Toms\Util>type pathpy32.bat
     @echo off
     rem Add Python 3.2.0 to path
     path C:\Python32;C:\Python32\Scripts;%path%
     path
And yes, I have one .bat file each for 2.6, 2.7, 3.1, 3.2 and then 
the Perl versions and then the ...

Note that you may want to remove the defaulted PATH additions for 
Python that each command window starts with.   Control Panel / System 
/ Advanced System Settings / Environment Variables / System Variables 
, double-click on 'Path' and edit as needed (carefully).


If you really want to use file associations so that you can simply 
double-click on 'icons' and execute programs, you need to delve into 
Windows registry hacks and tools.  (that's icky)

Tim mentioned 'assoc' and that most any Python install will have 
already 'associated' the file extensions for Python.  Check using 
something like:
   C:\Toms>assoc | grep -i pyth
     .py=Python.File
     .pyc=Python.CompiledFile
     .pyo=Python.CompiledFile
     .pyw=Python.NoConFile
(or   assoc | find /I "Python"   if you don't have Cygwin installed)

But the part you want to be changing as you switch versions is the 
"file type" associations, via command 'ftype'.  Check using something like:
   C:\Toms>ftype | grep -i pyth
     Python.CompiledFile="C:\Python32\python.exe" "%1" %*
     Python.File="C:\Python32\python.exe" "%1" %*
     Python.NoConFile="C:\Python32\pythonw.exe" "%1" %*

To update you can run something like:
   C:\Windows\system32>ftype Python.File="C:\Python27\python.exe" "%1" %*
     Python.File="C:\Python27\python.exe" "%1" %*
You may need to start a command window with  "Run as 
Administrator"  in order to be able to update those values.

And since you might want/need to update all three of those ftype 
values when switching between versions, you'll want to put them in a 
.bat file, and a separate one for each version.  (Hmm, maybe that'll 
let you double-click on an icon for the batch files to switch more 
easily between versions?)

The corresponding Windows registry keys for all this are:
     Computer\HKEY_CLASSES_ROOT\.py
     Computer\HKEY_CLASSES_ROOT\Python.File
     Computer\HKEY_CLASSES_ROOT\Python.File\shell\open\command 
"C:\Python32\python.exe" "%1" %*
     Computer\HKEY_CLASSES_ROOT\Python.File\shell\Edit with 
IDLE\command  "C:\Python32\pythonw.exe" 
"C:\Python32\Lib\idlelib\idle.pyw" -e "%1"
and so on.


-- 
I'm a pessimist about probabilities; I'm an optimist about possibilities.
     Lewis Mumford  (1895-1990)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110308/d33b8aba/attachment.html>


More information about the Python-list mailing list