How to upgrade your pip package to the latest version
Pip is the defacto tool for managing and installing your Python packages. It lets you install third-party software packages that are listed in the Python Package Index (PyPi), extending functionality for developers and allowing regular users to install certain applications written in Python.
Pip is usually bundled with Python and updates automatically, but you might want to manually upgrade and manage it. 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 latest 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 again very easy process. Just run the following:
python -m pip install --upgrade pip
Bear in mind that this command will try 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 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 rollback 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 manually update individual Python packages. We can use matplotlib as an example:
pip3 install --upgrade matplotlib
That about covers it. Pip is a versatile and useful tool and know you should now understand it a little better.
If you like to do your development in the cloud, feel free to check out our high-speed, anonymous VPS servers.