Here is notes to keep both Python 2 and Python 3 working on Windows.
New in Python 3.3
Start from Python 3.3, there is a
py.exe
installed to %SystemRoot% directory, which is helpful when multiple versions of Python installed.
py -2
and py
starts Python 2.x
py -3
starts Python 3.x
Use shebang in Python scripts
In favor of py.exe, shebang in Python scripts can be recognized on Windows.
#! python 3
for Python 3.x
#! python 2
for Python 2.x
Installation order matters
If you install python3 first and then Python 2, the setup program of Python 2 will overwrite the .py file association, such that a Python 3 script with shebang
#!python 3
will be executed by Python 2. So the better order is install Python 2 first and then Python 3.
Don’t need to add python to PATH
If both Python 2 and Python 3 executables are on
PATH, then there will be confusion. Instead of add Python to
PATH and call
python your-script.py
, the following command also work
your-script.py
.
No comments:
Post a Comment