How to create python2.7 virtualenv on Ubuntu 20.04

7,544

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

Share:
7,544

Related videos on Youtube

Gryu
Author by

Gryu

Nothing special

Updated on September 18, 2022

Comments

  • Gryu
    Gryu over 1 year

    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?

  • questionto42standswithUkraine
    questionto42standswithUkraine over 2 years
    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.