Skip to content

Instantly share code, notes, and snippets.

@bahostetterlewis
Last active September 29, 2016 07:45
Show Gist options
  • Save bahostetterlewis/5615946 to your computer and use it in GitHub Desktop.
Save bahostetterlewis/5615946 to your computer and use it in GitHub Desktop.
Update all pip packages!
#!/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)
# SOURCE: http://stackoverflow.com/questions/2720014/upgrading-all-packages-with-pip
# placed here for my easy finding
import pip
from subprocess import call
for dist in pip.get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)
@jabbalaci
Copy link

Very nice script. I added some small changes:

#!/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)

Packages are sorted in ascending order by name in an ignore-case way. I use it to update packages globally, that's why the "sudo". If you execute it, it will simply print the commands (dry run). If they are OK, uncomment the last line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment