Python 3.5 create virtualenv with python2.7

Viewed 1802

I have Python 3.5 installed in my windows machine and that is the only version I have on my computer. I want to create a python2.7 virtual environment to try out a certain package. Is it possible to create a virtual environment with python2.7 binaries without installing Python 2.7 in my system?

2 Answers

You don't need to have your Python interpreter on $PATH, you can tell virtualenv where to find it. I found this blog post Installing Multiple Python Versions on Windows Using Virtualenv but the TL;DR is:

  1. Open Command Prompt and enter pip install virtualenv.
  2. Download the desired python version (do NOT add to PATH!), and remember the path\to\new_python.exe of the newly installed version.
  3. To create a virtualenv, open Command Prompt and enter virtualenv \path\to\env -p path\to\new_python.exe.
  4. To install packages:
    1. Activate virtualenv: open Command Prompt and enter path\to\env\Scripts\activate.bat.
    2. Install desired packages with pip.
    3. Deactivate with deactivate.

Note python3 -m venv \path\to\env doesn't seem to suppport the -p parameter, you have to use virtualenv.

Related