Skip to content

Instantly share code, notes, and snippets.

@wangjiezhe
Last active August 29, 2015 14:08
Show Gist options
  • Save wangjiezhe/dfa9e5a20408317e9160 to your computer and use it in GitHub Desktop.
Save wangjiezhe/dfa9e5a20408317e9160 to your computer and use it in GitHub Desktop.
pip upgrade all
#!/usr/bin/env bash
cat << EOF | tee ~/.zshrc
PIP_UPGRADE="$(pwd)/pip_upgrade.py"
alias pip-upgrade="sudo python \${PIP_UPGRADE}"
alias pip3-upgrade="sudo python3 \${PIP_UPGRADE}"
EOF
# -*- coding: utf-8 -*-
'''
Use pip to upgrade all packages.
'''
from __future__ import print_function
import sys
import pip
from subprocess import call
if sys.version_info[0] > 2:
PIP = 'pip3'
else:
PIP = 'pip'
for dist in pip.get_installed_distributions():
if 'site-packages' in dist.location:
try:
call([PIP, 'install', '--upgrade', dist.key])
# call(PIP + "install --upgrade" + dist.key, shell=True)
except pip.PipError as exc:
print(exc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment