Skip to content

Instantly share code, notes, and snippets.

@bmuller
Created August 2, 2016 18:27
Show Gist options
  • Save bmuller/eb79ba3e5cda2c0d03ad488125075790 to your computer and use it in GitHub Desktop.
Save bmuller/eb79ba3e5cda2c0d03ad488125075790 to your computer and use it in GitHub Desktop.
venv function for dealing with virtualenv
function venv {
if [ "$1" == "" ]; then
echo "Currently using python in: "
dirname $(dirname $(which python))
echo
echo "Use: 'venv <name> [version]' to change. Version is 2.7 by default"
else
mkdir -p $HOME/.virtualenvs
if [ ! -d "$HOME/.virtualenvs/$1" ]; then
if [ "$2" == "" ]; then
/usr/local/bin/virtualenv $HOME/.virtualenvs/$1
else
/usr/local/bin/virtualenv $HOME/.virtualenvs/$1 -p python$2
fi
. $HOME/.virtualenvs/$1/bin/activate
pip install --upgrade pip
else
. $HOME/.virtualenvs/$1/bin/activate
fi
echo "Using virtual env in $HOME/.virtualenvs/$1; use 'deactivate' to disable."
export PS1="\u@\h \w$ "
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment