My .bashrc has this:
enable-pyenv () {
# Load pyenv automatically by adding
# the following to your profile:
export PATH=\"$HOME/.pyenv/bin:$PATH\"
This bash function removes pyenv paths and unsets environment variables. (I have just extended shivams sed
command, which may not work on BSD systems.)
function deactivate-pyenv {
# check that virtual environment is not currently active
if [ ! -z ${PYENV_VIRTUAL_ENV+x} ]; then
echo ""
echo "Cannot proceed while virtual environment is active"
echo ""
return 1
fi
# remove pyenv paths
export PATH=`echo $PATH | tr ':' '\n' | sed '/pyenv/d' | tr '\n' ':' | sed -r 's/:$/\n/'`
# unset pyenv environment variables
unset "${!PYENV@}"
}