How to keep python virtualenvs while updating ubuntu?

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.

0

2 Answers

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

$ git clone ~/.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.

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like