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
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.