Monday, January 5, 2009

Keeping and Switching Multiple Python Version on Windows

Assuming you have python 2.5 and python 2.6 installed.

Here is what you need to do :-

1. Right click on My Computer, under advance, environment variables.
Change all c:\python25 or c:\python26 path that u can find here to C:\python2x.
That includes c:\python2x\scripts, c:\python2x\lib, c:\python2x

2. Rename your c:\python25 (or whatever it is) to c:\python25.bin
Rename your c:\python26 (whatever it is) to c:\python26

3. type this to your command prompt (admin rights) :
ftype Python.CompiledFile=C:\Python2x\python.exe "%1" %*
ftype Python.File=C:\Python2x\python.exe "%1" %*

4. Create 2 batch file :
batch file 1.
xcopy c:\python25 c:\python2x /s /I

batch file 2.
xcopy c:\python26 c:\python2x /s /I

5. Fixup all the scripts dependencies.
For eg, goto c:\python25.bin\scripts, open up easy_install-2.5-script.py
Change the first line to : #!C:\Python2x\python.exe

You can repeat step 5 for other modules like nosetests, coverage etc. Else you will get the dreadful message "Cannot find Python executable ....."


Now, if you want to use python 2.5, just run the batch file 1 in your command prompt.
If you want to use python 2.6, just run batch file 2 in your command prompt.

There you go....