Moving to Python 3.0 (part2)

Goto start of series| Goto next in series

Not too long ago, I posted this query on comp.lang.py

I'd like to install both 2.6 and 3.0 together on the same Windows
(Vista) machine, so I can test programs under both versions.

Is it possible to install both versions on the same Windows machine in
such a way that they are both easily available and don't interfere with
one another?  I'm concerned, for example, that if I install both, the
second installation will over-write some Python entry in the registry.

I received four replies. They all were very helpful, and I recommend that you look at them for yourself: http://groups.google.com/group/comp.lang.python/browse_thread/thread/8dcb36c8d4c8e607#

Since what I want to do is pretty simple, for me they boil down to:

It's easy - the registry isn't used except to associate files.
The associations are made with the most-recently-installed version.

I currently have 2.4, 2.5, 2.6 and 3.0 on my Windows machine.

-- Steve Holden

and

Use batch scripts to setup your PATH and PYTHONPATH. This will not
solve the file association problem, but you can probably set up your
"SEND TO" folder to handle the different versions.

-- Dutch Masters

Setting up the batch file was easy. Here’s an example batch file called p30.bat. You can easily adapt it to run Python 2.5 or 2.6 or whatever.

@echo off
::---------------------------------------------------------
:: Name of this batch file is p30.bat
::---------------------------------------------------------

::---------------------------------------------------------
:: set up the constant PYDIR that controls what version
:: of Python we want this batch file to run.
::---------------------------------------------------------
:: To create p25.bat, p26.bat, p31.bat, etc., copy this file
:: to a file with the new name and change only this line.
::---------------------------------------------------------
SET PYDIR=c:\Python30

::---------------------------------------------------------
:: set PYTHONPATH so it includes the site-packages directory
:: of the right version of Python
::---------------------------------------------------------
:: For convenience, I include C:\pyapps, where I keep some
:: Python utilities, but you don't need to do that.
::---------------------------------------------------------
SET PYTHONPATH=C:\pyapps;%PYDIR%\Lib\site-packages

::---------------------------------------------------------
:: Save the PATH setting, so we can restore it later
::---------------------------------------------------------
SET SAVEPATH=%PATH%

::---------------------------------------------------------
:: reset PATH so it includes the PYDIR directory, where
:: the Python executable lives.
::---------------------------------------------------------
PATH=%PYDIR%;%PATH%

::---------------------------------------------------------
:: run the desired Python executable, passing it at least
:: the name of the Python script file that we want to run.
::---------------------------------------------------------
python.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

::---------------------------------------------------------
:: restore the PATH setting
::---------------------------------------------------------
PATH=%SAVEPATH%

::---------------------------------------------------------
:: clean up the environment variables that we created
::---------------------------------------------------------
SET SAVEPATH=
SET PYTHONPATH=
SET PYDIR=

Now, to test easygui under 2.6 and 3.0, I can simply do this:

p26 easygui.py

or

p30 easygui.py
About these ads