2

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?

shrekh
  • 161
  • 4
  • 14

1 Answers1

2

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 )

gelonida
  • 5,327
  • 2
  • 23
  • 41
  • after running this command, I am getting `can't open file '2.7': [Errno 2] No such file or directory"` – shrekh May 27 '20 at 07:57
  • 1
    I don't have a windows PC at hand. I think I just forgot the `-` before the `2.7` Please retry. Meanwhile I try to find online documentation for the python launcher to be sure this is the right syntax – gelonida May 27 '20 at 08:10
  • elaborated on my answer. Please tell me if it still doesn't work – gelonida May 27 '20 at 08:16
  • even though I have virtualenv installed, it is still showing me `No module named venv`, I tried with virtualenv as well but still got the same error – shrekh May 27 '20 at 08:38
  • I am so sorry. Did not even see it before. `venv` and `virtualenv` are two distinct modules. `venv` was only introduced from python 3.3 and above. For python 2.7. you can use `virtualenv` . Perhaps you can use `venv` from your python 3 version to create a virtualenv for python 2.7, but I don't think so. First quick searches don't indicate this – gelonida May 27 '20 at 22:00