How to update a specific package using pip

Sometimes, packages in Python can get outdated so there is a need to update the packages. Also for security and performance issues, we need to update the packages so that we can fix the issues. To upgrade packages in Python we can make use of pip in Python. Thus, in this tutorial, we will learn how to update a specific or particular package using pip.

List outdated packages using pip

Pip has a command with the list as the option which lists all the packages that are installed on your local computer. Along with the list option, we can make use of the outdated flag. Using this flag, all of the outdated packages will be displayed. We might thus want to update any of the outdated packages.

The syntax of the command is:

pip list --outdated

oudated packages using pip

Upgrade a specific Python package using pip

In the previous steps, we have already got a list of all the outdated packages.  To update a specific package in Python using the following mentioned command.

pip install <package-name> --upgrade

We could also use the following command instead of the above-mentioned command.

pip install <package-name> -U

We will thus try to upgrade the Pillow package using the following command.

pip install Pillow -U

How to update a specific package using pip

Thus we have successfully converted the Pillow package from version 9.2.0 to 9.3.0 using the upgrade flag of the pip command.

Update the package to a specific version

Sometimes, we might want to update the package to only a specific version and not the most recent version due to memory-capacity issues. Therefore to upgrade a package to only a specific version we make use of the following command:

pip install --upgrade <package-name>==<version>

We will try to upgrade the sqlparse package to a specific version 0.4.3 using the following command:

pip install --upgrade sqlparse==0.4.3

Update the package to a specific version

Thus we have reached the end of this tutorial on how to update specific packages in Python using pip. To learn more about pip in Python click on the following link: Upgrade all Python packages with pip at once

Leave a Reply

Your email address will not be published. Required fields are marked *