3

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?

10
  • Have you tried python -m venv project? Commented May 27, 2020 at 7:41
  • Have you checked that python is in your $PATH? Commented May 27, 2020 at 7:57
  • @arsho where to specify the version when using python -m venv project Commented May 27, 2020 at 8:03
  • In command prompt / terminal write: python --version to see what python version is default in your system. Commented May 27, 2020 at 8:39
  • @arsho 3.7.6 is the default version Commented May 27, 2020 at 8:42

1 Answer 1

3

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 )

Sign up to request clarification or add additional context in comments.

5 Comments

after running this command, I am getting can't open file '2.7': [Errno 2] No such file or directory"
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
elaborated on my answer. Please tell me if it still doesn't work
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
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.