Archive
Posts Tagged ‘update packages’
update all pip packages
May 22, 2013
Leave a comment
Problem
You want to update all the pip-installed Python packages on your system.
Solution
At http://stackoverflow.com/questions/2720014/ 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():
dists.append(dist.project_name)
for dist_name in sorted(dists, key=lambda s: s.lower()):
cmd = "sudo pip install {0} -U".format(dist_name)
print '#', cmd
#os.system(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: https://github.com/jabbalaci/update-pip-packages.
Categories: python
pip, update, update packages
