Pip upgrade all packages at once with a one-liner command

pip upgrade all
Image: pip upgrade all (License: CC-BY-SA Marcelo Canina)

pip upgrade all the virtual environment packages

Published:
Last modified:
Tags Python , Django , Pip

Overview

If you are using Python there is a high chance you are using virtual environments, and also probably you are using PIP1.

When working with these projects you start working with a requirements.txt file where all your packages versions being used are defined, which starts growing with time and some packages starts to be outdated.

Unfortunately there is no command to upgrade all of them at once and be up to date with all your project dependencies.

Command

This is a Linux one-liner that takes all the contents of the requirements file and upgrades them one by one..


$ pip3 list -o --format columns|  cut -d' ' -f1|xargs -n1 pip install -U

Explanation

Let’s explain how that command works.

  • pip3 list -o: shows the outdated packages
    • --format columns: specifies how to print the output
  • cut -d' ': split the input by spaces
    • -f1: and take the first field of each line
  • xargs -n1: use at most 1 arg by command line
    • pip install -U: upgrade the package

$ pip3 list -o --format columns
Package                   Version   Latest     Type 
------------------------- --------- ---------- -----
beautifulsoup4            4.6.3     4.7.1      wheel
certifi                   2018.8.24 2018.11.29 wheel
Django                    2.1.1     2.1.5      wheel
django-allauth            0.37.1    0.38.0     sdist
django-autocomplete-light 3.3.1     3.3.2      sdist
django-sendgrid-v5        0.7.0     0.7.1      wheel
Faker                     0.9.1     1.0.2      wheel
idna                      2.7       2.8        wheel
oauthlib                  2.1.0     3.0.1      wheel
pip                       18.1      19.0.1     wheel
psycopg2-binary           2.7.5     2.7.7      wheel
pycountry                 18.5.26   18.12.8    wheel
python-dateutil           2.7.3     2.7.5      wheel
pytz                      2018.5    2018.9     wheel
requests                  2.19.1    2.21.0     wheel
requests-oauthlib         1.0.0     1.2.0      wheel
setuptools                40.6.3    40.7.2     wheel
six                       1.11.0    1.12.0     wheel
urllib3                   1.23      1.24.1     wheel
whitenoise                4.1       4.1.2      wheel
$ pip3 list -o --format columns|  cut -d' ' -f1
Package
-------------------------
beautifulsoup4
certifi
Django
django-allauth
django-autocomplete-light
django-sendgrid-v5
Faker
idna
oauthlib
pip
psycopg2-binary
pycountry
python-dateutil
pytz
requests
requests-oauthlib
setuptools
six
urllib3
whitenoise
$ pip3 list -o --format columns|  cut -d' ' -f1|xargs -n1 pip install -U

.....

Collecting beautifulsoup4
  Using cached https://files.pythonhosted.org/packages/1d/5d/3260694a59df0ec52f8b4883f5d23b130bc237602a1411fa670eae12351e/beautifulsoup4-4.7.1-py3-none-any.whl
Collecting soupsieve>=1.2 (from beautifulsoup4)
  Using cached https://files.pythonhosted.org/packages/bf/b3/2473abf05c4950c6a829ed5dcbc40d8b56d4351d15d6939c8ffb7c6b1a14/soupsieve-1.7.3-py2.py3-none-any.whl
Installing collected packages: soupsieve, beautifulsoup4
  Found existing installation: beautifulsoup4 4.6.3
    Uninstalling beautifulsoup4-4.6.3:
      Successfully uninstalled beautifulsoup4-4.6.3
Successfully installed beautifulsoup4-4.7.1 soupsieve-1.7.3

....


References


  1. The PyPA recommended tool for installing Python packages ↩︎

Uruguay
Marcelo Canina
I'm Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.
comments powered by Disqus


This article shows a one-liner command to upgrade all the packages present in PIP's requirements.txt file at once.

Clutter-free software concepts.
Translations English Español

Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.

Powered by SimpleIT Hugo Theme

·