[Tutor] more py revisited

Jeff Shannon jeff at ccvcorp.com
Mon Aug 25 13:03:04 EDT 2003


SGD wrote:

> I would like to install multiple instances of python on windows XP,
> specifically 2.2.3 and 2.3.    
> Is this possible? 

Yes, it is.  They'll be installed (by default) in C:\Python22 and 
C:\Python23 respectively.  There's a few things to be aware of, though...

First off, compiled extensions (pyd files) are only usable with the 
Python version that they were compiled for, and each version has its 
own site-packages directory.  So (as you apparently already know) each 
version needs to have packages installed for it independently.

Of course, Windows can only associate the .py and .pyw extensions with 
a single executable, so the normal file association will follow 
whatever version of Python was installed last.

> Say I'm using an IDE connected to 2.3, how would I run
> a 2.2.3 script from that same IDE (any IDE really, I use so many, so
> hard to decide which I like best)? Or better yet, specifying which run
> time version I would like to run a script from explorer? Is it legal to
> rename one of the exe's to say, python.exe->py22.exe and
> pythonw.exe->pyw22.exe, to use windows "right click" "open with", or
> something similar?

You won't be able to get them both to work well from a Python IDE 
(IDLE or PythonWin), because those are Python packages that are 
limited to a single version.  However, if you're using a completely 
separate IDE, you should be able to identify the executables as 
c:\python22\python.exe and c:\python23\python.exe respectively. 
Changing the name of the executables would probably work. 
(Effectively the same thing does work on *nix, using symlinks; I see 
no reason why it wouldn't on Windows.)  You could also set up 
batchfiles (py22.bat and py23.bat) that would pass the script name 
(and any commandline options) along to the correct executable. 
Depending on how demanding Python is about modules' file extensions, 
it may be possible to rename some files .py2 and associate that 
extension with a different executable than .py (I haven't tried this 
and I'm not sure whether this will interfere with import mechanisms).

The only real problems you're facing here are ones of Windows 
configuration -- you have a single file extension that you want to 
alternately associate with two different executables.  Looking at it 
from this perspective, it may be possible to write a script that 
changes that association back and forth.  Run the script and all .py 
files run in Py22, run it again and all .py files run in Py23.  It 
really depends on how extensively you want to get into your Windows 
configuration.

Jeff Shannon
Technician/Programmer
Credit International




More information about the Tutor mailing list