pylauncher How to run different python versions in cmd
python download (3)
This question already has an answer here:
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.
Python 3.3 introduces Python Launcher for Windows that is installed into
pyw.exe by the installer. The installer also creates associations with
.pyw. Then add
#!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.
py.exe looks for
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.
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.
C:\Python35;C:\Python35\Scripts;C:\Python27;C:\Python27\Scriptsto environment variable
- Go to
python3.exe, also to
- restart your command window.
python2 scriptname.py, or
python3 scriptname.pyin command line to switch the version you like.
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.
.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.