4

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?

JeanVuda
  • 1,738
  • 14
  • 29

2 Answers2

1

To use a different Python interpreter, that interpreter needs to be on $PATH, which means a binary on your machine.

see --> https://stackoverflow.com/a/45293556/6813490

Zach Valenta
  • 1,783
  • 1
  • 20
  • 35
1

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.

parsley72
  • 8,449
  • 8
  • 65
  • 98