Pip upgrade all packages at once with a one-liner command
pip upgrade all the virtual environment packages
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 linepip 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
- https://pip.pypa.io/en/stable/reference/pip_list/
- http://man7.org/linux/man-pages/man1/cut.1.html
- http://man7.org/linux/man-pages/man1/xargs.1.html
- https://pip.pypa.io/en/stable/reference/pip_install/
The PyPA recommended tool for installing Python packages ↩︎
- Solve Selenium WebDriverException executable needs to be in PATH error messageApril 24, 2020
- Pip upgrade all packages at once with a one-liner command
- Test Files Creating a Temporal Directory in Python UnittestsSeptember 2, 2018
- How to Translate a Python Project With Gettext the Easy WayAugust 29, 2018
Behave Testing
Django webframework
- August 1, 2023
- How to create a reusable Django app and distribute it with PIP or publish to pypi.orgJune 29, 2021
- How To Serve Multiple Django Applications with uWSGI and Nginx in Ubuntu 20.04October 26, 2020
- How to add favicon to Django in 4 stepsSeptember 3, 2020
- Categories in Django with BreadcrumbsAugust 30, 2020
- How To Migrate From SQLite To PostgreSQL In Django In 3 stepsAugust 28, 2020
- Practical guide to internationalize a Django app in 5 steps.August 24, 2020
- Disable new users singup when using Django's allauth packageSeptember 3, 2019
- How to add ads.txt to Django as requested by Google AdsenseAugust 30, 2019
- Have multiple submit buttons for the same Django formJuly 2, 2019
- Better Testing with Page Object Design in DjangoMay 1, 2019
- Generating slugs automatically in Django without packages - Two easy and solid approachesFebruary 14, 2019
- How to set up Django tests to use a free PostgreSQL database in HerokuFebruary 13, 2019
- Dynamically adding forms to a Django FormSet with an add button using jQueryFebruary 6, 2019
- Use of Django's static templatetag in css file to set a background imageFebruary 1, 2019
- Activate Django's manage.py commands completion in Bash in 2 stepsJanuary 29, 2019
- Sending Emails with Django using SendGrid in 3 easy stepsJanuary 9, 2019
- Adding Users to Your Django Project With A Custom User ModelSeptember 21, 2018
- Setting Up A Factory For One To Many Relationships In FactoryboyApril 17, 2018
- Generate UML class diagrams from django modelsMarch 24, 2018
- Set Up Ubuntu To Serve A Django Website Step By StepJuly 3, 2017
- Django Project Directory StructureJuly 16, 2016
- How to Have Different Django Settings for Development and Production, and environment isolationJune 10, 2016
- Django OverviewJune 2, 2016
Django Forms
- Adding a Cancel button in Django class-based views, editing views and formsJuly 15, 2019
- Using Django Model Primary Key in Custom Forms THE RIGHT WAYJuly 13, 2019
- Django formset handling with class based views, custom errors and validationJuly 4, 2019
- How To Use Bootstrap 4 In Django FormsMay 25, 2018
- Understanding Django FormsApril 30, 2018
- How To Create A Form In DjangoJuly 29, 2016
Flask web microframework
- Understanding Flask's context conceptJanuary 26, 2017
- Avoid Using Flask Instance Folder When Deploying To HerokuJanuary 24, 2017
- Managing Environment Configuration Variables In Flask With DotenvJanuary 24, 2017
- Organize A Flask Project To Handle Production And Development Environments EffectivelyJanuary 11, 2017
- An Overview Of Flask Main Concepts And How It WorksDecember 31, 2016
Python Language
- Python Tools To Write Better CodeNovember 7, 2017
- Python Language Main Concepts And SummaryJune 11, 2017
- Python notesMay 30, 2016
Python Language Concepts
- Understanding How Python Packages Modules And Imports WorkJanuary 2, 2017
- Python Language Basic ConceptsJune 14, 2016
Python Environment
- Understanding Python 3 virtual environments different approachesJanuary 15, 2019
- Python Projects Isolation Using Virtual EnvironmentsJune 10, 2016
Articles
Subcategories
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
·