you can install both python 2 and python 3 in your machine but you can not use both in single code editor in same time. To use both at same time you have to open one IDEs with python 2 and another IDEs with python 3.
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.
Python version 3 is not backwardly compatible with Python 2. Many recent developers are creating libraries which you can only use with Python 3. Many older libraries created for Python 2 is not forward-compatible.
The official solution for coexistence seems to be the Python Launcher for Windows, PEP 397 which was included in Python 3.3.0. Installing the release dumps py.exe
and pyw.exe
launchers into %SYSTEMROOT%
(C:\Windows
) which is then associated with py
and pyw
scripts, respectively.
In order to use the new launcher (without manually setting up your own associations to it), leave the "Register Extensions" option enabled. I'm not quite sure why, but on my machine it left Py 2.7 as the "default" (of the launcher).
Running scripts by calling them directly from the command line will route them through the launcher and parse the shebang (if it exists). You can also explicitly call the launcher and use switches: py -3 mypy2script.py
.
All manner of shebangs seem to work
#!C:\Python33\python.exe
#!python3
#!/usr/bin/env python3
as well as wanton abuses
#! notepad.exe
Here's my setup:
C:\Python34
(the default install path) and change python.exe to python3.exeC:\Python27\;C:\Python27\Scripts\;C:\Python34\;C:\Python34\Scripts\;
Now in command line you can use python
for 2.7 and python3
for 3.4.
From version 3.3 Python introduced Launcher for Windows utility https://docs.python.org/3/using/windows.html#python-launcher-for-windows.
So to be able to use multiple versions of Python:
You can have both installed.
You should write this in front of your script:
#!/bin/env python2.7
or, eventually...
#!/bin/env python3.6
My solution works perfectly with Unix, after a quick search on Google, here is the Windows solution:
#!c:/Python/python3_6.exe -u
Same thing: in front of your script.
I'm using 2.5, 2.6, and 3.0 from the shell with one line batch scripts of the form:
:: The @ symbol at the start turns off the prompt from displaying the command.
:: The % represents an argument, while the * means all of them.
@c:\programs\pythonX.Y\python.exe %*
Name them pythonX.Y.bat
and put them somewhere in your PATH. Copy the file for the preferred minor version (i.e. the latest) to pythonX.bat
. (E.g. copy python2.6.bat python2.bat
.) Then you can use python2 file.py
from anywhere.
However, this doesn't help or even affect the Windows file association situation. For that you'll need a launcher program that reads the #!
line, and then associate that with .py and .pyw files.
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