5

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?

  • 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 at 10:08
6

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
    
| improve this answer | |
  • Followed the process but after step 2 I'm getting error E: Package 'python-virtualenv' has no installation candidate – AnupRaj Jun 29 at 2:54
  • Thanks @AnupRaj. I have updated the answer with latest command to install virtualenv in step2. You can follow these steps again. – jay vaghani Jun 30 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.