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.
As a standard, it is recommended to use the python3 command or python3. 7 to select a specific version. The py.exe launcher will automatically select the most recent version of Python you've installed. You can also use commands like py -3.7 to select a particular version, or py --list to see which versions can be used.
There's nothing wrong with having two versions of python installed, and it's actually quite common to do so. Usually, one would install them with different names ( python vs python3 , for example) to avoid confusion though.
Install multiple python versions For Windows users, I recommend using the Windows x86-64 executable installer option if you work on a 64bit system. Otherwise, just use the Windows x86 executable installer . After locating the install option for the specific version, just press the download link.
Follow the same steps for installing Python 2 and Python 3 versions. Now you have two Python version installed on your system. But, how to choose a particular Python version to run your Python code or script. Simply add the following line of code as the first line to your any Python script. You can print the Python version to ensure it.
Running a different copy of Python is as easy as starting the correct executable. You mention that you've started a python instance, from the command line, by simply typing python.
You can simply download Python software from its official website and install it. For more detail, choose below installation steps based on the operating system. Follow the same steps for installing Python 2 and Python 3 versions. Now you have two Python version installed on your system.
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.
I also met the case to use both python2 and python3 on my Windows machine. Here's how i resolved it:
C:\Python35;C:\Python35\Scripts;C:\Python27;C:\Python27\Scripts
to environment variable PATH
.C:\Python35
to rename python.exe
to python3.exe
, also to C:\Python27
, rename python.exe
to python2.exe
.python2 scriptname.py
, or python3 scriptname.py
in command line to switch the version you like.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With