8

I want to run an application that uses python2.7 version, but by default python2.7 is not installed. When I tried to use:

$ virtualenv -p python2 flaskold

It returned:

RuntimeError: failed to find interpreter for Builtin discover of python_spec='python2'

How could I create python2.7 virtual environment on Ubuntu 20.04 which goes without python 2.7 support?

Gryu
  • 8,004
  • I understand what the question is from reading its answer, but I think this question could be improved by editing the question to make it more explicit. – karel Dec 01 '20 at 10:19
  • Why not just install python-is-python2 package and use as normal? – doug Dec 01 '20 at 14:02

2 Answers2

11

Install python2:

sudo apt install python2 virtualenv

Universe repository is being used for this. You could add it if not added the next way: $ sudo add-apt-repository universe.

Create virtual environment using python2.7 the next way:

$ virtualenv --python=$(which python2) /path/to/newenv/folder/

$(which python2) will return path to python2 which would be correct argument. python2 could be used to start interpreter in terminal, but could not be used as an argument value for --python directive

Gryu
  • 8,004
  • Works. And yes, you need to create the directory of the venv yourself, that is, installing a venv does not create a parent venv folder on its own. – questionto42 Dec 09 '21 at 09:02
2

For Python3

sudo apt install python3-venv

For Python2

sudo pip2 install virtualenv
Jatin
  • 23