How to upgrade all Python packages with pip

ID : 307

viewed : 164

Tags : pythonpippython

Top 5 Answer for How to upgrade all Python packages with pip

vote vote


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 

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).

vote vote


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) 
vote vote


To upgrade all local packages; you could use pip-review:

$ pip install pip-review $ pip-review --local --interactive 

pip-review is a fork of pip-tools. See pip-tools issue mentioned by @knedlsepp. pip-review package works but pip-tools package no longer works.

pip-review works on Windows since version 0.5.

vote vote


The following works on Windows and should be good for others too ($ is whatever directory you're in, in the command prompt. For example, C:/Users/Username).


$ pip freeze > requirements.txt 

Open the text file, replace the == with >=, or have sed do it for you:

$ sed -i 's/==/>=/g' requirements.txt 

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.

Another way:

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.

vote vote


Use pipupgrade!

$ 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. It is compatible with Python 2.7+, Python 3.4+ and pip 9+, pip 10+, pip 18+, pip 19+.

Enter image description here

Note: I'm the author of the tool.

Top 3 video Explaining How to upgrade all Python packages with pip