Skip to content

Instantly share code, notes, and snippets.

@SeppPenner
Last active October 10, 2019 14:28
Show Gist options
  • Save SeppPenner/efc73891480b67c561aac7ba47df9df7 to your computer and use it in GitHub Desktop.
Save SeppPenner/efc73891480b67c561aac7ba47df9df7 to your computer and use it in GitHub Desktop.
Python upgrade Pip packages

For pip < 10.0.1:

import pip
from subprocess import call

packages = [dist.project_name for dist in pip.get_installed_distributions()]
for package in packages:
	try:
		call("pip install --upgrade " + package, shell=True)
	except Exception as e:
		print("Error: " + str(e))
print('Update finished')			

For pip >= 10.0.1:

import pkg_resources
from subprocess import call

packages = [dist.project_name for dist in pkg_resources.working_set]
for package in packages:
	try:
		call("pip install --upgrade " + package, shell=True)
	except Exception as e:
		print("type error: " + str(e))
import pkg_resources
from subprocess import call
packages = [dist.project_name for dist in pkg_resources.working_set]
for package in packages:
try:
call("pip install --upgrade " + package, shell=True)
except Exception as e:
print("Error: " + str(e))
print('Update finished')
import pip
from subprocess import call
packages = [dist.project_name for dist in pip.get_installed_distributions()]
for package in packages:
try:
call("pip install --upgrade " + package, shell=True)
except Exception as e:
print("Error: " + str(e))
print('Update finished')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment