0

A friend of mine told me that every python virtualenv he had in its ubuntu 18 OS became useless when he upgraded to ubuntu 20, and I think it's because of the new python version (3.8). If anyone could give me some sort of solution for keeping these virtualenvs "alive", I would appreciate it. I've found this question but it isn't my case (I guess). Thanks in advance.

2 Answers2

1

I had the same issue when upgrading to Ubuntu 20.04. The reason is that Python 3.6 and 3.7 are no longer included in the system packages. If you've created a virtual environment for 3.6/ 3.7 using virtualenv, it still expects a matching system interpreter. You can install these Python versions via the deadsnakes PPA in Ubuntu 20.04:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.6 # and python3.6-venv, python3.6-dev if needed

In many cases, this won't suffice: Check ls -la| grep python3 in your venv/bin-directory and you'll see links like:

lrwxrwxrwx 1 me me    16 Mai 10 16:20 python -> /usr/bin/python3
lrwxrwxrwx 1 me me     6 Mai 10 16:20 python3 -> python
lrwxrwxrwx 1 me me     6 Mai 10 16:20 python3.6 -> python

This environment links against the default Python instead of specifically linking against Python 3.6. You'll need to change the base link like this:

ln -sf /usr/bin/python3.6 python

Then, the environment should continue to work. I haven't tested it myself though and just upgraded my environments instead.

fynnlyte
  • 111
0

Another option is pyenv which allows you to quickly install different python versions locally.

$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ . ~/.bashrc
$ pyenv install 3.6.9

You can easily switch between python versions using:

$ pyenv global 3.6.9

That should get you back to the python version you need.

rtaft
  • 1,825