Upgrading all packages with pip

0 votes
asked Apr 27, 2010 by thedjpetersen

Is it possible to upgrade all Python packages at one time with pip?

Note that there is a feature request for this on the official issue tracker.

29 Answers

0 votes
answered Apr 10, 2010 by rbp

There isn't a built-in flag yet, but you can use

pip freeze --local | 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!

Relevant edits:

  • Added a grep to skip "-e" package definitions, as suggested by @jawache (Yes, you could replace grep+cut with sed or awk or perl or...).
  • Newer versions of pip allow you to list outdated packages:

    pip list --outdated --format=freeze
  • Added -n1 to xargs, prevents stopping everything if updating one package fails (thanks @andsens)

0 votes
answered Jan 10, 2011 by janrito

You can just print the packages that are outdated

pip freeze | cut -d = -f 1 | xargs -n 1 pip search | grep -B2 'LATEST:'
0 votes
answered Jan 13, 2011 by brunobord

when using a virtualenv and if you just want to upgrade packages added to your virtualenv, you may want to do:

pip install `pip freeze -l | cut --fields=1 -d = -` --upgrade
0 votes
answered Jan 24, 2011 by tobu

Here is my variation on rbp's answer, which bypasses "editable" and development distributions. It shares two flaws of the original: it re-downloads and reinstalls unnecessarily; and an error on one package will prevent the upgrade of every package after that.

pip freeze |sed -ne 's/==.*//p' |xargs pip install -U --

Related bug reports, a bit disjointed after the migration from bitbucket:

0 votes
answered Apr 30, 2011 by ramana

You can use the following Python code. Unlike pip freeze, this will not print warnings and FIXME errors.

import pip
from subprocess import call

for dist in pip.get_installed_distributions():
    call("pip install --upgrade " + dist.project_name, shell=True)
0 votes
answered Jan 3, 2012 by tkr

From https://github.com/cakebread/yolk :

$ pip install -U `yolk -U | awk '{print $1}' | uniq`

however you need to get yolk first:

$ sudo pip install -U yolk
0 votes
answered Jan 27, 2012 by chbrown

@Ramana's worked the best for me, of those here, but I had to add a few catches:

import pip
for dist in pip.get_installed_distributions():
    if 'site-packages' in dist.location:
            pip.call_subprocess(['pip', 'install', '-U', dist.key])
        except Exception, exc:
            print exc

The site-packages check excludes my development packages, because they are not located in the system site-packages directory. The try-except simply skips packages that have been removed from PyPI.

@endolith: I was hoping for an easy pip.install(dist.key, upgrade=True), too, but it doesn't look like pip was meant to be used by anything but the command line (the docs don't mention the internal API, and the pip developers didn't use docstrings).

0 votes
answered Apr 25, 2012 by piotr-dobrogost

Windows version after consulting excellent documentation for FOR by Rob van der Woude

for /F "delims===" %i in ('pip freeze -l') do pip install -U %i

0 votes
answered Jan 22, 2013 by salman-abbas

One-liner version of @Ramana's answer.

python -c 'import pip, subprocess; [subprocess.call("pip install -U " + d.project_name, shell=1) for d in pip.get_installed_distributions()]'


0 votes
answered Apr 29, 2013 by jfs

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.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter