Last active
August 29, 2015 13:57
-
-
Save phoikoi/9356353 to your computer and use it in GitHub Desktop.
Shell script for modifying python virtualenv scripts after moving them to new location
This file contains hidden or 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
# When using virtualenvwrapper to manage your python virtual environments, | |
# if you need to move your virtualenvs to a new location, mostly all that is | |
# necessary is to modify your shell initialization scripts (~/.bash_profile, etc.) | |
# But there's a problem waiting to bite you: each virtualenv's activate script has | |
# the path to the virtualenv hard-coded into it by mkvirtualenv. So you need | |
# to edit each one to change this. Otherwise things will not work after moving | |
# things to the new location. This gist is a sample of how to change all the | |
# virtualenvs at once with a little shell script and sed. Run this script | |
# after you've changed the variables in your bash_profile and restarted your | |
# shell. | |
OLD_PATH=${1} # first argument is old virtualenv base path e.g. .old-virtualenvs | |
NEW_PATH=${2} # second argument is new virtualenv base path e.g. .new-virtualenvs | |
for v in $(find ${WORKON_HOME} -name 'activate' | grep 'bin/activate') | |
do | |
sed -i -e "s:${OLD_PATH}:${NEW_PATH}:g" ${v} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment