Skip to content

Instantly share code, notes, and snippets.

@codeliger
Created May 19, 2018 02:06
Show Gist options
  • Select an option

  • Save codeliger/0d8dfe397935bd5ecc4ea57930490a6c to your computer and use it in GitHub Desktop.

Select an option

Save codeliger/0d8dfe397935bd5ecc4ea57930490a6c to your computer and use it in GitHub Desktop.
Upgrades all pip packages
import subprocess
import json
CMD_LIST = 'pip list --outdated --format json'
CMD_UPDATE = 'pip install --upgrade {}'
result = subprocess.run(CMD_LIST.split(),stdout=subprocess.PIPE)
packages = json.loads(result.stdout)
for package in packages:
name = package['name']
print('Upgrading {}'.format(name))
cp = subprocess.run(CMD_UPDATE.format(name).split())
if cp.returncode != 0:
print('Possible failure of package upgrade {}\n{}'.format(name,cp.stderr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment