Cannot switch Python with pyenv

后端 未结 6 908
忘掉有多难
忘掉有多难 2021-01-30 08:36

I would like to use pyenv to switch python2 and python3.

I successfully downloaded python2 and python3 and pyenv with following codes.

brew install pyenv         


        
6条回答
  •  猫巷女王i
    2021-01-30 09:23

    This answer is only for people that are using Fish shell and find this thread. Pyenv uses shims, ref, so in order to make pyenv work with your fish shell you have to edit your ~/.config/fish/config.fish file an append the pyen shim directory at the beginning of your $PATH variable. Here is what my config.fish looks like.

    ### PATH ###
    set default_path /usr/local/bin /usr/bin /usr/sbin /bin /sbin
    set macports /opt/local/bin
    set androiddev ~/Android\ Development/platform-tools/
    set rbenv ~/.rbenv/shims/
    set pyenv ~/.pyenv/shims/
    set anaconda /Users/m4punk/anaconda/bin/
    set pg_config /Applications/Postgres.app/Contents/Versions/9.5/bin/
    
    
    ### Virtual Enviroment Wrapper ###
    
    set -g VIRTUALFISH_HOME ~/Documents/Coding/python/virtualenvs
    set -g VIRTUALFISH_DEFAULT_PYTHON /usr/local/bin/python3
    eval (python -m virtualfish)
    
    ### NVM Settings ###
    set -g NVM_DIR ~/.nvm
    
    set -gx PATH $pyenv $default_path $macports $androiddev $rbenv $pg_config
    
    setenv EDITOR sublime
    

    The relevant lines here are

    set pyenv ~/.pyenv/shims/
    

    and

    set -gx PATH $pyenv $default_path $macports $androiddev $rbenv $pg_config
    

    The first creates a variable for the pyenv shim path, the second adds it to the front of your path variable. Just save&close, restarted your terminal session and you should be all set.

提交回复
热议问题