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.
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
Remove/Uninstall Python Package
The simplest way to remove a package is by using pip uninstall
List Python Package
To list installed packages use pip list
List outdated Python Packages
It's possible to list outdated python packages using the --outdated
CLI instruction.
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.
To simply upgrade all python packages using pipupgrade
run the below command.
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
.