How To Update/Upgrade A Python Package with Pip? – POFTUT

How To Update/Upgrade A Python Package with Pip?


Pip is a popular command used to manage Python packages.  Pip command is also used for updating/upgrading already installed Python packages.

List Installed Python Packages

Before updating or upgrading an installed Python package we will list already installed packages. We will use the list command which will display the complete name and the version of the installed packages.

$ pip list

$ pip2 list

$ pip3 list
List Installed Packages
List Installed Packages

Check If A Python Package Is Installed

In the previous example, we have just listed all installed packages and versions. We can also check if a specific python package is already installed. We will also use grep command by providing the name of the package we want to check.

$ pip list | grep ufw
$ pip list | grep zipstream
$ pip list | grep django
$ pip list | grep xml
$ pip list | grep pip
Check If A Python Package Is Installed
Check If A Python Package Is Installed

List Outdated Python Packages

Pip command also provides --outdated options with the list command which will list outdated and already installed python packages.

$ pip list --outdated

$ pip2 list --outdated

$ pip3 list --outdated
List Outdated Python Packages
List Outdated Python Packages

Upgrade/Update Python Package To The Latest Version

We will use the install command with the --upgrade option and also provide the package name. In this example, we will update/upgrade the package named Django to the latest version. We will also provide the --user option. Alternatively to the --upgrade we can use -U which is the short form.

$ pip install --user --upgrade django

$ pip2 install --user --upgrade django

$ pip3 install --user --upgrade django
Upgrade/Update Python Package To The Latest Version
Upgrade/Update Python Package To The Latest Version

From the screenshot, we see that first the Django version 2.0 is found. Django version 2.0 is uninstalled and then Django version 2.2.5 is installed which will complete the upgrade/update of the Django.

LEARN MORE  How To Install Specific Version Of Python Package with Pip?

Upgrade/Update Python Package To The Specific Version

In the previous example, we have updated the Django python package to the latest version. We can also update/upgrade a python package into a specific version which is not the latest. In this example, we will upgrade/update a specific version which is not the latest with the equal signs. We will not use the --upgrade option but specify the upgraded version.

$ pip install --user django==2.2

$ pip2 install --user django==2.2

$ pip3 install --user django==2.2
Upgrade/Update Python Package To The Specific Version
Upgrade/Update Python Package To The Specific Version

We can see that the currently installed version is Django 2.0 but we will upgrade it into version 2.2 .

Downgrade Python Package To The Specific Version

We can also downgrade the installed package into a specific version. We will specify the Python package name with the version we want to downgrade by using equation signs like below. In this example, we will downgrade the Django package to version 2.0.

$ pip install --user django==2

$ pip2 install --user django==2

$ pip3 install --user django==2
Downgrade Python Package To The Specific Version
Downgrade Python Package To The Specific Version

Leave a Comment