Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Upgrade all packages using pip
#!/usr/bin/env python
from __future__ import print_function
from sys import stderr
from pip import get_installed_distributions
from pip.commands import install
from pip.exceptions import InstallationError
print_error = lambda error: print(
'{0}: {1}'.format(error.__class__.__name__, error.message),
if __name__ == '__main__':
print('Trying to upgrade all python packages (using pip)')
install_cmd = install.InstallCommand()
for package in get_installed_distributions():
options, args = install_cmd.parse_args([package.project_name])
options.upgrade = True
print('Attempting to upgrade: {project_name!r}'.format(project_name=package.project_name))
try:, args)
except OSError as e:
if e.errno == 13: # permissions error
except (InstallationError, IOError) as e:

This comment has been minimized.

Copy link
Owner Author

SamuelMarks commented Apr 27, 2015

Note that this is a response to a StackOverflow question: Upgrading all packages with pip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.