How to run multiple versions of Python on Windows using virtualenv

You have Python (i.e. 3.5.2) installed on your Windows (in this case Win10) and now for some reason you need to install a different version of Python (i.e. 2.7.14) in parallel and have your Python code run on it.

For this purpose we use a feature in Python called virtualenv. Please take the steps below:

1- If you don’t have Python, download it from here and install it on your machine.

2- Open a command prompt with Administrative privilege and check the version of Python by running the following command:

Python --version

3- Now run the command below to download and install the virtualenv package:

pip install virtualenv

4- Now install Python version 2.7.14 (or any other version you wish) using the MSI or EXE file from the Python website. During the installation you need to specify the installation path (you will need this path in the next step). For this example our installation path is C:\Python27

5- Now in the command prompt window go to any directory where you want to create a new Python virtual environment, and run the following command:

virtualenv.exe -p C:\Python27\python.exe py27env

The command above creates a folder in the path you are in. The directory/environment name for my case is py27env. It could have any other name.

6- Now activate your environment by running the following command. This is only a one-time task to do:


7- The next time you want to run Python 2.7.14 simply go to the same folder and run the Python.exe in that directory and it will run Python in that virtual environment for you with the version you had specified:

py27env\Scripts\python.exe --version

Hope you find these easy steps pretty useful…

Leave a Reply

Your email address will not be published. Required fields are marked *