How to upgrade all Python packages with pip?
There isn't a built-in flag yet, but you can use
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
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!
In older version of
pip, you can use this instead:
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
grep is to skip editable ("-e") package definitions, as suggested by @jawache. (Yes, you could replace
-n1 flag for
xargs prevents stopping everything if updating one package fails (thanks @andsens).
Read more... Read less...
You can use the following Python code. Unlike
pip freeze, this will not print warnings and FIXME errors.
For pip < 10.0.1
import pip from subprocess import call packages = [dist.project_name for dist in pip.get_installed_distributions()] call("pip install --upgrade " + ' '.join(packages), shell=True)
For pip >= 10.0.1
import pkg_resources from subprocess import call packages = [dist.project_name for dist in pkg_resources.working_set] call("pip install --upgrade " + ' '.join(packages), shell=True)
To upgrade all local packages; you could use
$ pip install pip-review $ pip-review --local --interactive
pip-review works on Windows since version 0.5.
Works on Windows. Should be good for others too. ($ is whatever directory you're in, in command prompt. eg. C:/Users/Username>)
$ pip freeze > requirements.txt
open the text file, replace the
>= , and execute
$ pip install -r requirements.txt --upgrade
If you have a problem with a certain package stalling the upgrade (numpy sometimes), just go to the directory ($), comment out the name (add a # before it) and run the upgrade again. You can later uncomment that section back. This is also great for copying python global environments.
I also like the pip-review method:
py2 $ pip install pip-review $ pip-review --local --interactive py3 $ pip3 install pip-review $ py -3 -m pip_review --local --interactive
You can select 'a' to upgrade all packages; if one upgrade fails, run it again and it continues at the next one.
$ pip install pipupgrade $ pipupgrade --verbose --latest --yes
pipupgrade helps you upgrade your system, local or packages from a
requirements.txt file! It also selectively upgrades packages that don't break change. pipupgrade also ensures to upgrade packages present within multiple Python environments. Compatible with Python2.7+, Python3.4+ and pip9+, pip10+, pip18+, pip19+.
NOTE: I'm the author of the tool.