Created
December 10, 2015 15:40
-
-
Save myersjustinc/7ce4024207d2ad19f77c to your computer and use it in GitHub Desktop.
Update Python version in virtualenvs after upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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