On 21 July, 15:19, Dave Angel <da...@dejaviewphoto.com> wrote: > ChrisW wrote: > > Hi, > > > 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 > > task? > > > Thanks, > > Chris > > 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 > > c:\progfiles\python26\python.exe %* > > 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 > and pythonw31.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
Thanks for this - this way made a bit more sense to me. I've now got C:\commands with the 4 .bat files in, and C:\commands in my path. It all seems to work :) I think I've missed the point of the @ though - it doesn't seem to make any difference.. I'm also a bit confused with the associations - since I've got python 2.6 and 3.1, surely the command I type (python26 or python31) is the only way to force a script to be run using a specific interpreter at runtime without having to change the .bat file every time I want to run a script using 3.1 instead of 2.6? -- http://mail.python.org/mailman/listinfo/python-list