5

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?

2
  • 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 1, 2020 at 10:19
  • Why not just install python-is-python2 package and use as normal?
    – doug
    Dec 1, 2020 at 14:02

2 Answers 2

9

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

1
  • 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. Dec 9, 2021 at 9:02
1

For Python3

sudo apt install python3-venv

For Python2

sudo pip2 install virtualenv

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .