snippetpythonCritical
How to upgrade all Python packages with pip
Viewed 0 times
allhowpackagespythonupgradepipwith
Problem
Is it possible to upgrade all Python packages at one time with
Note: that there is a feature request for this on the official issue tracker.
pip?Note: that there is a feature request for this on the official issue tracker.
Solution
There isn't a built-in flag yet. Starting with pip version 22.3, the
If you are using
Note: there are infinite potential variations for this. I'm trying to keep this answer short and simple, but please do suggest variations in the comments!
--outdated and --format=freeze have become mutually exclusive. Use Python, to parse the JSON output:pip --disable-pip-version-check list --outdated --format=json | python -c "import json, sys; print('\n'.join([x['name'] for x in json.load(sys.stdin)]))" | xargs -n1 pip install -U
If you are using
pippip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
For older versions of pip:
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
-
The grep is to skip editable ("-e") package definitions, as suggested by @jawache. (Yes, you could replace grep+cut with sed or awk or perl or...).
-
The -n1 flag for xargs` prevents stopping everything if updating one package fails (thanks @andsens).Note: there are infinite potential variations for this. I'm trying to keep this answer short and simple, but please do suggest variations in the comments!
Context
Stack Overflow Q#2720014, score: 2951
Revisions (0)
No revisions yet.