Deactivate pyenv in current shell

2020-06-16 01:41发布

问题:

My .bashrc has this:

enable-pyenv () {
    # Load pyenv automatically by adding
    # the following to your profile:

    export PATH="$HOME/.pyenv/bin:$PATH"
    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
}

enable-pyenv

Which enables pyenv. In some situations, I want to (temporarily) disable pyenv. How can I do this?

回答1:

If you want to use the python version from your system:

pyenv local system

https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-global https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local



回答2:

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.



回答3:

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.



回答4:

None of the posted answers worked for me but the following did:

$ echo "" > /home/myusername/.pyenv/version


回答5:

Try pyenv deactivate, to manually deactivate the virtual env.

Doc here: https://github.com/yyuu/pyenv-virtualenv



标签: python pyenv