Last active
August 29, 2015 13:56
-
-
Save bittner/8830745 to your computer and use it in GitHub Desktop.
Automatically activate virtualenv in Python development. (Source this file from within .bashrc)
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
# From: "Automatically activate virtualenv" by Kurt Neufeld | |
# URL: http://www.burgundywall.com/tech/automatically-activate-virtualenv/ | |
# Date: 16-Oct-2013 | |
# | |
# Usage: | |
# | |
# 1. Create an empty .venv file in your project home: touch .venv | |
# 2. Put this file in your home directory: cp .bash_virtenv ~/ | |
# 3. Include it in ~/.bashrc as follows: | |
# | |
# if [ -f ~/.bash_virtenv ]; then | |
# . ~/.bash_virtenv | |
# fi | |
export PREVPWD=`pwd` | |
export PREVENV_PATH= | |
handle_virtualenv() { | |
if [ "$PWD" != "$PREVPWD" ]; then | |
PREVPWD="$PWD"; | |
if [ -n "$PREVENV_PATH" ]; then | |
if [ "`echo "$PWD" | grep -c $PREVENV_PATH`" = "0" ]; then | |
deactivate | |
unalias python 2> /dev/null | |
PREVENV_PATH= | |
fi | |
fi | |
# activate virtualenv dynamically | |
if [ -e "$PWD/.venv" ] && [ "$PWD" != "$PREVENV_PATH" ]; then | |
PREVENV_PATH="$PWD" | |
workon `basename $PWD` | |
fi | |
fi | |
} | |
export PROMPT_COMMAND=handle_virtualenv | |
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages' | |
export WORKON_HOME=~/.virtualenvs | |
#source `which virtualenvwrapper.sh` # Mac only |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment