shrekh
shrekh

Reputation: 171

Create a virtual environment with python version 2.7 with existing version as 3.7

I want to create a virtual environment with python version 2.7 on windows, however, after installing virtualenv and running python 2.7 -m venv project I am receiving an error RuntimeError: failed to find interpreter for Builtin discover of python_spec='2.7' I have downloaded the 2.7 version of python as well, what am I missing?

Upvotes: 3

Views: 5484

Answers (1)

gelonida
gelonida

Reputation: 5630

venv is a package that was only introduced from python 3.3 and above. ( https://docs.python.org/3/library/venv.html ) I never used it.

You might use virtualenv, that exists also for python 2.7. but must be installed with following command (but you did this probably already)

py -2.7 -m pip install virtualenv

You then type

py -2.7 -m virtualenv project_dir

if none of above works, then please type py -2.7 -m pip freeze and post the output.

You can also type

py -2.7 -c "import sys ; print(sys.executable, sys.version_info)"

To see what python 2.7 version you have exactly installed.

The difference between py.exe and python.exe:

On windows py.exe is the python launcher, that tries to keep track of all installed python versions and of potentially activated virtualenvs and launches the one you want.

python will try to find the python executable in the search path. and it would yield the first python in the path.

py is the windows python launcher which will locate the python executables with help of environment variables and the registry and which allows with the -version (e.g. -2.7) switch to select which version of python you want to call.

( Documentation for the python launcher on windows: https://docs.python.org/3/using/windows.html#from-the-command-line )

Upvotes: 3

Related Questions