Posts Tagged ‘update packages’

update all pip packages

You want to update all the pip-installed Python packages on your system.

At there is a very nice little script for this task:

import pip
from subprocess import call

for dist in pip.get_installed_distributions():
    call("pip install --upgrade " + dist.project_name, shell=True)

I modified it a bit to update packages in ascending order by name in an ignore-case way:

#!/usr/bin/env python

import os
import pip

dists = []
for dist in pip.get_installed_distributions():

for dist_name in sorted(dists, key=lambda s: s.lower()):
    cmd = "sudo pip install {0} -U".format(dist_name)
    print '#', cmd

I want to update the packages globally, that’s why the “sudo“. If you run it, it will just print the commands to the stdout (dry run). If everything is OK, uncomment the last line.

Update (20140121)
I made a github project of it:

Categories: python Tags: , ,