How to install, remove, list and upgrade python packages using PIP

Packages are regularly updated in order to include security patches, provide new features or optimize the existing code.

How to install, remove, list and upgrade python packages using PIP

New releases of python packages are done every once in while depending on the developer's update frequency. You might sometime find yourself stuck with out-of-date packages that require upgrading. This is at no point the fault of the developer. Its just packages are regularly updated in order to include security patches, provide new features or optimize the existing code.

PIP is the most commonly used python package manager. PIP provides an easy way to install, list, and remove python packages. Many may not know that PIP also contains an option to upgrade a package.

Install Python Package

The simplest to install a package is by using pip install

pip install <package-name>
Example install pip package

Remove/Uninstall Python Package

The simplest way to remove a package is by using pip uninstall

pip uninstall <package-name>
Example remove/uninstall pip package

List Python Package

To list installed packages use pip list

pip list
List installed python packages

List outdated Python Packages

It's possible to list outdated python packages using the --outdated CLI instruction.

pip list --outdated
List outdated packages 

Upgrading A Python Package

The simplest way to upgrade a python package is by using the --upgrade CLI instruction while running pip install.

pip install <package-name> --upgrade

However, the above command does not upgrade all your installed packages.

Upgrading All Python Packages

In order to upgrade all python packages we require a custom solution as PIP does not offer the solution to this problem natively.

pip install -U `pip list --outdated | awk 'NR>2 {print $1}'`

NB: -U is the shorthand for --upgrade

Upgrading All Python Packages Using Third Party

If the above solution is not working for you. You can use a third-party package manager to upgrade your packages. The most popular is pipupgrade.

First, you would need to install pipupgrade.

pip install pipupgrade
Install pipupgrade

To simply upgrade all python packages using pipupgrade run the below command.

pipupgrade --latest --yes
Upgrade all packages using pipupgrade

Conclusion

Whether you are a beginner or a pro programmer the above pip commands should put you up to speed with PIP. These are not all PIP  commands but the above are the commonly used CLI commands that you would need for basic python package management. To find all the commands you can run using pip run pip --help.

Subscribe to Bluedoa Digest

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
alexander@example.com
Subscribe