This guide is about how to deal with multiple python versions on windows.
When installing python, two executables will be added to the windows directory: C:/Windows/py.exe and C:/Windows/pyw.exe, which you can use to run any of the python versions installed.
You can run scripts like so.
py -3 file.py # use the most recent python 3.x version py -3 # open in interactive mode py -2 file.py # use the most recent python 2.x version py file.py # use the version specified by the shebang # otherwise use the default version py -3.4 file.py # use this specific python version py -3 -m pip [arguments] # can also access pip like this
The python version can be specified in the script file itself, with the addition of a line in the beginning of the script, the shebang.
#! interpreter [optional arguments] #! python2 -- most recent python 2.x #! python3 -- most recent python 3.x #! python3.4 -- this specific version
You can add both directories to the 'PATH', and rename the executables.
After installing both versions, you'll have two directories installed, for example in C:/Python27 and C:/Python34. Now you can add them both to the 'PATH' environment variable.
To add to the 'PATH' variable.
At this point, you can run 'python' in the command line, but it will only run one of the versions. To be able to distinguish between the different versions, you need to rename the python executables, for example renaming C:/Python27/python.exe to C:/Python27/python2.exe, and doing the same for the python3 executable, will allow you to run the desired version by calling either the python2 or the python3 command.
There's several ways to open the command line in windows.