Upgrading Python CLI packages

We usually care about keeping our terminal tools up to date. pip however doesn't provide an easy way to upgrade CLI packages. Here's a workaround.

First, let's write a script that prints out all installed Python packages that provide a CLI:

import pkg_resources

for pkg in pkg_resources.working_set:
    if "console_scripts" in pkg.get_entry_map():

Save the script in a file named packages.py. We can then pass the list of packages to pip to upgrade them:

python packages.py | xargs pip install --upgrade

Depending on your setup, you might want to use python3/pip3 instead.