Deactivate pyenv in current shell

前端 未结 7 2066
日久生厌
日久生厌 2021-02-13 02:22

My .bashrc has this:

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

    export PATH=\"$HOME/.pyenv/bin:$PATH\"
         


        
相关标签:
7条回答
  • 2021-02-13 02:51

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

    $ echo "" > /home/myusername/.pyenv/version
    
    0 讨论(0)
  • 2021-02-13 02:51

    Try pyenv deactivate, to manually deactivate the virtual env.

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

    0 讨论(0)
  • 2021-02-13 02:58

    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.

    0 讨论(0)
  • 2021-02-13 03:04

    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.

    0 讨论(0)
  • 2021-02-13 03:10

    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@}"
    
    }
    
    0 讨论(0)
  • 2021-02-13 03:13

    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.

    0 讨论(0)
提交回复
热议问题