Ubuntu – Problem with creating Python 3.6 virtual environment on Ubuntu 20.04

20.04python3

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?

Best Answer

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
    
Related Question