How to upgrade pip package to the latest version

pip

Pip is a valuable tool for managing and installing Python packages. Here’s how to upgrade pip on various operating systems.

Pip is the de facto tool for managing and installing your Python packages. It allows you to install third-party software packages listed in the Python Package Index (PyPi), thereby extending functionality for developers and enabling regular users to install specific Python-based applications.

Pip is usually bundled with Python and updates automatically; however, you may want to upgrade and manage it manually. This is what we’ll be teaching you today. This process should work whether you’re using pip on Linux, Windows, or macOS.

Checking your pip version

The first thing you’ll probably want to do is check which pip version you have in the first place. You can then compare that to the latest published version to see whether you should upgrade. The command for this is thankfully very simple:

pip --version

Your output should look something like this:

pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

You can check what the latest pip version is here and decide whether to update accordingly. At the time of writing, the newest pip version is 22.0.4. Our server is on 20.0.2, so an upgrade is definitely in order.

How to upgrade pip

Upgrading pip is a very easy process again. Just run the following:

python -m pip install --upgrade pip

Please note that this command will attempt to uninstall the current version and replace it with the new one.

Upgrading pip on Ubuntu

If you see the message Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr, it’s because you’re using Ubuntu. The Ubuntu version of pip has been modified to disallow upgrades via this method. Instead, you must use the Ubuntu packaging system.

sudo apt update

sudo apt install pip

Note that the Ubuntu package probably won’t be up to date. If you do need the latest version, you can download get-pip.py and run it. However, it’s worth noting that running pip as the root user can cause broken permissions and conflicting behavior with the system package manager. You are generally better off using a virtual environment.

Here are the commands you need:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

python3 get-pip.py

How to downgrade pip

If you do find that you need to roll back your pip version due to bugs, incompatibilities, or any other reason, find the version number you want to roll back to and then run this command:

python -m pip install pip==your.version.number

How to update Python packages with pip

Pip also allows you to update individual Python packages manually. We can use matplotlib as an example:

pip3 install --upgrade matplotlib

That about covers it. Pip is a versatile and valuable tool, and it’s worth understanding a little better.

Share the Post:

Related Posts