Multiple versions of python
davea at dejaviewphoto.com
Tue Jul 21 16:19:42 CEST 2009
> I have installed 2 versions of python on my Windows XP computer - I
> originally had 3.0.1, but then found that the MySQL module only
> supported 2.*, so I've now installed that. I have found that if I
> change the Windows Environment Variable path, then I can change the
> version of python called when I type 'python' into a command line.
> However, I'd like to be able to choose which version I use. I know
> that if I change C:\Python26\python.exe to
> C:\Python26\python2.exe and C:\Python30\python.exe to C:
> \Python26\python3.exe, then typing 'python2' or 'python3' will invoke
> the correct interpreter. However, is it safe just to rename the
> executable files? Is there a more elegant way to achieve the same
The elegant way is to have a batch directory on your PATH ( I use
m:\t\bat ) and put your *.bat files there. I do NOT put any python
installations on the PATH.
For example, I have a batch file called: m:\t\bat\python26.bat
The %* syntax means pass all arguments through to the program.
Once it all works, you can add an "@" in front of the c: in order to
suppress echoing the command. At that point, it'll look and work the
same way as what you did, but without modifying anything in the install
directory. (You may want python26.bat, pythonw26.bat, python31.bat
The other thing you may want to do in a batch file is to change the file
associations so that you can run the .py file directly, without typing
"python" or "pythonw" in front of it.
The relevant Windows commands are: assoc and ftype And on a
related note, you may want to edit the PATHEXT environment variable, to
add .PY and .PYW
More information about the Python-list