How can I configure windows command dialog to run different python versions in it? For example when I type python2 it runs python 2.7 and when I type python3 it runs python 3.3? I know how to configure environment variables for one version but two? I mean something like Linux terminal.
3 Answers
I also met the case to use both python2 and python3 on my Windows machine. Here's how i resolved it:
- download python2x and python3x, installed them.
 - add 
C:\Python35;C:\Python35\Scripts;C:\Python27;C:\Python27\Scriptsto environment variablePATH. - Go to 
C:\Python35to renamepython.exetopython3.exe, also toC:\Python27, renamepython.exetopython2.exe. - restart your command window.
 - type 
python2 scriptname.py, orpython3 scriptname.pyin command line to switch the version you like. 
2 Comments
python.exe files, how does doing that affect things when doing minor upgrades, say from version 2.7.x to 2.7.x+y, which normally would both be located in the same C:\Python27 directory?Python 3.3 introduces Python Launcher for Windows that is installed into c:\Windows\ as py.exe and pyw.exe by the installer. The installer also creates associations with .py and .pyw. Then add #!python3 or #!python2 as the first lline. No need to add anything to the PATH environment variable.
Update: Just install Python 3.3 from the official python.org/download. It will add also the launcher. Then add the first line to your script that has the .py extension. Then you can launch the script by simply typing the scriptname.py on the cmd line, od more explicitly by py scriptname.py, and also by double clicking on the scipt icon.
The py.exe looks for C:\PythonXX\python.exe where XX is related to the installed versions of Python at the computer. Say, you have Python 2.7.6 installed into C:\Python27, and Python 3.3.3 installed into C:\Python33. The first line in the script will be used by the Python launcher to choose one of the installed versions. The default (i.e. without telling the version explicitly) is to use the highest version of Python 2 that is available on the computer.
16 Comments
C:\Python33\python.exe to the C:\Python33\python3.exe. However, it is better to use explicitly py -3 scriptname.py. It is even better to put the information into the script, and then launch your scripts for either version the uniform way.python3.exe. However, using the Python Launcher for Windows is better, and there is no need for doing such things.cmd. When using Python Launcher for Windows, the Python is not in the path at all -- nor the system, nor the user paths. That is because py.exe is in c:\Windows. And if you do not want to modify the script, you can always call py -3 myscript.py for Python 3 or py -2 myscript.py for Python 2. Default today for py myscript.py uses Python 3 interpreter.I would suggest using the Python Launcher for Windows utility that was introduced into Python 3.3. You can manually download and install it directly from the author's website for use with earlier versions of Python 2 and 3.
Regardless of how you obtain it, after installation it will have associated itself with all the standard Python file extensions (i.e. .py, .pyw, .pyc, and .pyo files). You'll not only be able to explicitly control which version is used at the command-prompt, but also on a script-by-script basis by adding Linux/Unix-y shebang #!/usr/bin/env pythonX comments at the beginning of your Python scripts.