This page looks best with JavaScript enabled

Update pip/pip3 to Python 3.8 in Ubuntu

 ·  ☕ 4 min read

I wanted to change my Python version associated with pip from 3.5 to 3.8. This proved nontrivial and totally undocumented anywhere I searched, so here’s an explanation of what I did so that I have a reference of what to do for next time, yay!

This guide describes the process for Ubuntu 18.04.4 LTS.

Changing version of Python3

Changing the version associated to python3 is pretty easy to find instructions about. If you have multiple versions installed, you just need to cd to /usr/bin, check what the path names are, and then use update-alternatives to configure which version is the default.

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

However, note from the comments here that using update-alternatives may be unsafe for some installers that expect python3 to be an older version of Python. Certainly, I would NOT use this to make python point to python3.8.

Changing version of Pip

But to change version of pip, I couldn’t really find easy documentation. Since pip is just a package manager, and not actual software, there is not as much concern about breaking any dependencies; I want to be able to type pip install instead of python3 -m pip install. This is already possible to do inside of all of my venvs, but outside of a venv, pip install gives the Python 3.5 pip, not Python 3.8.

When searching for how to do this, I found this Stack Overflow thread, but it only helped a little. So here’s the full process of what I did.

First, I uninstalled any current version of pip using apt:

sudo apt remove python-pip
sudo apt remove python3-pip

But pip3 -V still existed and gave the wrong version:

The command pip3 -V giving python 3.5 pip

So then I looked at my $PATH variable (echo $PATH):

The output of echo $PATH

And I randomly cd'd through folders til I got to /usr/local/bin, which had what I wanted:

The contents of /usr/local/bin

So then I ran:

rm pip
rm pip3
rm pip3.5

Then I restarted my shell, and because I had previously done the update-alternatives thing, I figured I could just run:

sudo apt install python3-pip
pip3 -V

And this did indeed now give me Python3.8 pip, but then I found out I had made a mistake.

A mistake

So previously, I had been playing around in /usr/bin (lol), and I had done a couple things:

The first was to create a symlink from pip3 to the pip package in my Python 3.8 installation:

ln -s pip3 /home/river/.local/lib/python3.8/site-packages/pip

The second was to create a symlink from pip to pip3:

sudo ln -s /usr/bin/pip3 pip

Turns out…this was NOT what I wanted to do.

The diagnosis

So now pip was working, but when I ran pip -V I got this warning:
The command pip -V with a warning

Here is the issue it’s mentioning. I didn’t find that too helpful, but I instead searched the actual text of the message, and came across this Stack Overflow thread which suggested that I run the following:

python3 -m pip install --upgrade --force-reinstall pip

The command to reinstall pip

What a helpful warning!

The resolution - actually a necessary setup step

So I added /home/river/.local/bin/ to my $PATH (before doing this, I echo $PATH'd just in case I messed up):

export PATH="/home/river/.local/bin/:$PATH"

And I also put it into ~/.profile and ~/.config/fish/config.fish per this Ask Ubuntu post.

Ok, now let’s try again:

pip -V
pip3 -V

The commands pip -V and pip3 -V with the right outputs!

Now let’s install my library:

Installing mwrogue

Yay! It worked!

Clean up the mistake

Now let’s just remove the bad symlinks from /usr/bin and make sure everything still works:

Removing bad symlinks & rechecking pip version

Yay!

Conclusion

Ignoring the detour we took, you need to:

  • Uninstall python3-pip & python-pip using apt
  • Remove the old pip files from /usr/local/bin
  • Reinstall python3-pip using apt
  • Add $HOME/.local/bin to your $PATH (also restart your shell to make sure you did this right)

And then pip and pip3 should both point to Python 3.8 pip instead of Python 3.5!

Now, let’s just hope I don’t have to update to 3.10 any time soon….

Share on

river
WRITTEN BY
River
River (RheingoldRiver) is a MediaWiki developer and the manager of Leaguepedia. She likes cats.


What's on this Page