My .bashrc has this:
enable-pyenv () {
# Load pyenv automatically by adding
# the following to your profile:
export PATH=\"$HOME/.pyenv/bin:$PATH\"
None of the posted answers worked for me but the following did:
$ echo "" > /home/myusername/.pyenv/version
Try pyenv deactivate
, to manually deactivate the virtual env.
Doc here: https://github.com/yyuu/pyenv-virtualenv
Try playing around with some variants of:
env -i bash
env -i bash -l
env -i bash --norc
env -i bash --norc --noprofile
This does not come without side effects as env -i
nukes your whole session and thus afterwards a lot of convenience like $HOME
is gone with the bathwater, but so is pyenv
.
I'm not sure that this will get rid of all traces of pyenv, but editing your $PATH
environment variable to get rid of the pyenv- or shim-containing paths seems to deactivate pyenv. Eg,
export PATH=`echo $PATH | python -c "import sys, re; print(':'.join(x for x in sys.stdin.read().strip().split(':') if not 'pyenv' in x))"`
If you want to be able to re-enable it, just store your previous $PATH
so you can restore it later.
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@}"
}
For me, what worked ultimately was the brute force method of removing all pyenv
paths from the $PATH
variable:
PATH=`echo $PATH | tr ':' '\n' | sed '/pyenv/d' | tr '\n' ':' | sed -r 's/:$/\n/'`
I wish pyenv
offered a better way by itself.