31

Ubuntu 20.04 has Python 3.6 and Python 3.8 support. Command python3 -m venv my_venv creates virtual environment with python 3.8 and it works as expected.

However, trying python3.6 -m venv my_venv3.6 does not work. The response I get is /usr/bin/python3.6: No module named venv.

I tried using virtualenv --python=/usr/bin/python3.6 my_venv3.6, which results in:

RuntimeError: failed to query /usr/bin/python3.6 with code 1 err: ...

I also tried installing sudo apt install python3.6-venv which results in:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package python3.6-venv is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python3.6-venv' has no installation candidate

Note that running python3.6 starts interactive python prompt with Python 3.6.9. I can also run scripts this way, so it seems that Python 3.6 is indeed usable on my system.

How can I start Python 3.6 virtual environment on Ubuntu 20.04?

2
  • I'm unable to add a comment to the previous answer (new user, not enough reputation points), but 20.04 does not have python-virtualenv. Rather, you will need to use: ``` apt-get install python3-virtualenv ``` Then to create your virtual environment for Python 3.6 you can simply do: ``` virtualenv -p python3.6 env ``` Hope this helps someone else.
    – gummy
    May 28, 2020 at 10:08
  • The venv package is not included in the regular python package. It has to be installed for each Python versions, e.g. sudo apt-get install python3.6-venv.
    – Pankrat
    Nov 20, 2020 at 8:21

2 Answers 2

55

Ubuntu 20.04 ships with default Python 3.8. So first you will need to install Python 3.6.

  1. Install python 3.6:

    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt-get update
    sudo apt-get install python3.6
    
  2. If the virtualenv package is not installed, run:

    apt-get update
    apt-get install python3-virtualenv
    
  3. Create a virtual environment:

    virtualenv -p /usr/bin/python3.6 venv
    
6
  • 1
    Followed the process but after step 2 I'm getting error E: Package 'python-virtualenv' has no installation candidate
    – AnupRaj
    Jun 29, 2020 at 2:54
  • Thanks @AnupRaj. I have updated the answer with latest command to install virtualenv in step2. You can follow these steps again. Jun 30, 2020 at 4:03
  • I had no luck either after creating even virtual environment. Oct 1, 2020 at 14:02
  • 1
    @JiteshSojitra Did you activate the virtual environment you created?. If not than use command source ./venv/bin/activate. Oct 2, 2020 at 9:41
  • 6
    As an alternative to step 2 & 3, you could sudo apt-get install python3.6-venv and python3.6 -m venv mypy36venv. More information can be found here: docs.python.org/3/tutorial/venv.html
    – Pankrat
    Nov 20, 2020 at 8:18
1

You can also do:

curl https://pyenv.run | bash
pyenv install 3.6.13
pyenv global 3.6.13
pyenv local 3.6.13
pip install virtualenv
virtualenv venv_ok

You must log in to answer this question.

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