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
I ran into the same problem and ended up making some changes to the way pyenv init
goes about setting up the shell but in the end it works the same. The only real difference from the guide on the pyenv github page is that I had to add the $(pyenv root)/bin
directory to my path too.
The reason I did this was to avoid long shell startup times from running eval "$(pyenv init -)"
and all the other .bash_profile
work that goes into my local shell environment. Just to be clear; Pyenv itself doesn't create a bad shell experience, in my humble opinion, but when you work with several languages that all have their own version management systems and tools that like to be initialized from the .profile with pyenv
, etc., the shell initialization process can get slow.
Here's the steps I took to set myself up, at a high view:
pyenv init
command so you can see
what it would have done for you.PATH
and shell environment vars into your .bash_profile
(or whatever file your distro uses).pyenv init
printed into your .bashrc
and source your .bashrc
from your .bash_profile
This is one way to get it done but it's better to use this as "pseudo-code". You should exchange .bash_profile
for whatever file your distro prefers.
$ pyenv init - # use the output for reference, it doesn't actually do anything
$ cat < ~/.bash_profile
export PYENV_SHELL=bash
PATH=$(pyenv root)/shims:$(pyenv root)/bin:$PATH
[ -f /usr/local/Cellar/pyenv/1.2.9/completions/pyenv.bash ] && . /usr/local/Cellar/pyenv/1.2.9/completions/pyenv.bash
[ -f ~/.bashrc ] && . ~/.bashrc
EOBP
The next bit updates your shell with a new bit of logic that we copied from the pyenv init
dry run from step 1, above.
$ cat < ~/.bashrc
# from $(pyenv init -)
pyenv() {
local command
command="${1:-}"
if [ "$#" -gt 0 ]; then
shift
fi
case "$command" in
rehash|shell)
eval "$(pyenv "sh-$command" "$@")";;
*)
command pyenv "$command" "$@";;
esac
}
EORC