I am always forgetting how to do this and so I thought I would throw this quick write-up together about how you can get Python 2 and 3 to play nicely together on Windows 7 and higher.
Edit: So be sure to let me know in the comments section below if this article helps you or if you run into some kind of issues! I am mostly running Python 3 on Mac and Linux these days but I definitely want to keep this post up to date with the proper way to do this.
To run Python 2 and 3 side by side on Windows
Install Python 2 - 64bit with default options (DO NOT check the option to add anything to the path)
Install Python 3 - 64bit with default options (DO NOT check the option to add anything to the path)
Python 2 and 3 will be installed with their default locations and you will notice that typing
python at the command line will now do nothing. This is fine.
The installers will install the Python launcher, which is two executables into your Windows directory:
To start the Python 2 interpreter
To run Python 2 pip
py -m pip list
To install Python 2 module
py -m pip install flask
To run Python 2 script
To get version number
To start the Python 3 interpreter
To run Python 3 pip
py -3 -m pip list
To install Python 3 module
py -3 -m pip install flask
To run Python 3 script
py -3 main.py
To get version number
py -3 --version
Create a virtual environment on the CLI with Python 3
# first install it py -3 -m pip install virtualenv # then create it py -3 -m virtualenv venv # activate it venv\Scripts\activate.bat
py determine the proper interpreter to run
#!python3 at the top of your script to let
py.exe determine whether to launch Python 2 or Python 3. Then you can launch either with something like
Great resources that helped me solve this issue
Donate if this Tutorial Helped You
Feel free to donate if this tutorial helped you! It helps support the costs of running this site (both in server costs and time costs) and helps keep me motivated to make more tutorials!
There are several ways to do so:
Buy something on Amazon by clicking on My Amazon Affiliate Link
Donate with your credit card using Donor Box! Donate
Donate with Crypto
Nano Address (Feeless, Reccommended):
Tutorials Coming soon to show you how to buy and send Crypto!