Skip to content

Instantly share code, notes, and snippets.

@myersjustinc
Created December 10, 2015 15:40
Show Gist options
  • Save myersjustinc/7ce4024207d2ad19f77c to your computer and use it in GitHub Desktop.
Save myersjustinc/7ce4024207d2ad19f77c to your computer and use it in GitHub Desktop.
Update Python version in virtualenvs after upgrade
#!/bin/bash
# When you upgrade your Python installation in Homebrew, any virtualenvs that
# relied on that Python installation will stop working because of some broken
# symlinks.
#
# Stéphane Wirtel documented a solution:
# http://wirtel.be/posts/en/2014/07/29/fix_virtualenv_python_brew/
#
# This automates that for all virtualenvs installed with virtualenvwrapper
# (http://virtualenvwrapper.readthedocs.org/) and properly checks whether the
# virtualenv expects Python 2 or Python 3.
venvs=$( find ${WORKON_HOME} -type d -depth 1 )
for venv in ${venvs}; do
python_version=$( ls -r ${venv}/lib | head -n 1 | grep -o '\d' | head -n 1 )
echo "$( basename ${venv} ): ${python_version}"
find ${venv} -type l -delete
virtualenv -p `which python${python_version}` ${venv}
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment