Skip to content

Instantly share code, notes, and snippets.

@ksze
Created December 14, 2012 13:48
Show Gist options
  • Save ksze/4285582 to your computer and use it in GitHub Desktop.
Save ksze/4285582 to your computer and use it in GitHub Desktop.
A simple Bash script to upgrade all pip packages in a virtualenv.
#!/usr/bin/env bash
# INSTALLATION
# ------------
# Put this script in the bin directory of your virtualenv and make it user executable:
# $ cp pip_upgrade_all.sh /path/to/your_virtualenv/bin/
# $ chmod u+x /path/to/your_virtualenv/bin/pip_upgrade_all.sh
# USAGE
# -----
# Run this script as an ordinary command:
# $ /path/to/your_virtualenv/bin/pip_upgrade_all.sh
#
# You don't need to activate the virtualenv beforehand; the script will do it for you.
# HOW THIS WORKS
# --------------
# This is a simple combination of two answers on StackOverflow:
# * http://stackoverflow.com/a/3452888/432483
# * http://stackoverflow.com/a/246128/432483
# Detect current path and store it in the Dir variable
Source="${BASH_SOURCE[0]}"
Dir="$(dirname "$Source")"
while [[ -h "$Source" ]]; do
Source="$(readlink "$Source")"
[[ $Source != /* ]] && Source="$Dir/$Source"
Dir="$(cd -P "$(dirname "$Source")" && pwd)"
done
Dir="$(cd -P "$(dirname "$Source")" && pwd)"
read -p "The detected path is '${Dir}'." bla
# Activate the correct virtualenv
. "$Dir/activate"
# Perform the actual upgrade
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment