Updating Python packages can be a hassle. There are many of them - it's hard to keep track of all the newest versions, and even when you decide what to update, you still have to update each of them manually.
Originally a part of the
pip-tools package, it now lives on as a standalone convenience wrapper around
pip. In this tutorial, we'll be covering how to update all packages with pip-review.
You can install
pip-review in a virtual environment, if you'd like to contain it, or system-wide. Naturally, installing
pip-review is done via
pip install pip-review ... Successfully installed pip-review-1.1.0
Help Page of pip-review
If you forget any of these commands or you simply want an overview of the command options:
pip-review -h usage: pip-review [-h] [--verbose] [--raw] [--interactive] [--auto] Keeps your Python packages fresh. Looking for a new maintainer! See https://github.com/jgonggrijp/pip-review/issues/76 optional arguments: -h, --help show this help message and exit --verbose, -v Show more output --raw, -r Print raw lines (suitable for passing to pip install) --interactive, -i Ask interactively to install updates --auto, -a Automatically install every update found Unrecognised arguments will be forwarded to pip list --outdated and pip install, so you can pass things such as --user, --pre and --timeout and they will do what you expect. See pip list -h and pip install -h for a full overview of the options.
Check All Package Versions with pip-review
Sometimes, you'd just want to check if there are any updates, before commiting to a potentially long update list. To check all package versions, you simply run:
pip-review scikit-learn==0.23.2 is available (you have 0.23.1) scipy==1.5.4 is available (you have 1.4.1) seaborn==0.11.0 is available (you have 0.10.1) ...
This gives you a report that lists all available package updates. Essentially, it calls
pip list – outdated. This has the advantage of allowing you decide which packages you'd like to update, if any at all.
Update All Packages with pip-review
Once you've identified if you'd like to update your packages, you can update them all, automatically, using:
pip-review --auto Collecting beautifulsoup4==4.9.3 Downloading beautifulsoup4-4.9.3-py3-none-any.whl (115 kB) ...
Running just this command alone - you’re set to go. It’s that simple.
Update All Packages Interactively with pip-review
If you perhaps don't wish to update some specific packages, you don't need to run the
--auto updater. If you launch the process as
--interactive, you can choose for each individual package whether you'd like to update it or no:
pip-review --interactive matplotlib==3.3.3 is available (you have 3.1.3) Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit N numpy==1.19.4 is available (you have 1.18.1) Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit Y pandas==1.1.5 is available (you have 1.0.3) Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit N ...
For each package, you have four options available, “Yes”, “No”, “All” and “Quit”.
Selecting “Yes” indicates you want that particular package added to the "to-be-updated-list". At the end every package on this list gets updated.
If you end up selecting “No” it would mean the package won't get updated. Selecting “All” means all packages moving forward will be added to the list. Finally, selecting “Quit” would mean
pip-review will skip all remaining packages and update only the ones you selected “Yes” to.
Prevent pip-review from Updating Certain Packages
In some situations, you might want to prevent certain packages from automatically updating when running
pip-review --auto. This could be perhaps to avoid dependencies issues, a common problem.
In these cases, you’d want to pin the specific packages you don't want to update. You can do this via a constraint file. A constraint file is a requirement file that only controls which version of a requirement is installed, not whether it is installed or not.
Free eBook: Git Essentials
Check out our hands-on, practical guide to learning Git, with best-practices, industry-accepted standards, and included cheat sheet. Stop Googling Git commands and actually learn it!
Its syntax and contents are identical to that of requirement files. There is one key difference:
Including a package in a constraints file doesn’t trigger installation of the package.
Let's make a
And now within it, we'll insert:
Updating packages using
pip can be tedious and time-consuming. And as as expected in the computer science world, a tool was born to automate this. In this article, we've gone over the
pip-review utility - how to install it, as well as how to use it to update packages in Python.