January 19 2015
pyenv lets you easily switch between multiple versions of Python
As always, I recommend to use homebrew to install
Assuming that you have already installed homebrew, to install
pyenv, you need
brew update brew install pyenv
This will also create a hidden folder under your user directory
~/.pyenv. In most cases,
you don’t have look at this directory.
pyenv, put the following into your
~/.zshrc if you are using zsh. I strongly recommend zsh. Try to install it via homebrew and give it a try.
export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)"
To enable shell completions, also add this to your shell config file
# for bash shell if [[ -f /usr/local/opt/pyenv/completions/pyenv.bash ]]; then source /usr/local/opt/pyenv/completions/pyenv.bash fi # for zsh shell if [[ -f /usr/local/opt/pyenv/completions/pyenv.zsh ]]; then source /usr/local/opt/pyenv/completions/pyenv.zsh fi
Resetting your shell terminal, and check if
pyenv runs. To list supported versions of python
pyenv install --list
For academic use, I strongly recommend
anaconda3-2.1.0. (Also, give a try to
Installation is a piece of cake.
pyenv install anaconda3-2.1.0
It may take some time for the installation process to finish.
To show available versions of python
You should see
anaconda3-2.1.0. System python is the version of python first found along the
anaconda3-2.1.0in the current terminal session.
pyenv shell anaconda3-2.1.0 # check python version python -V # Python 3.4.1 :: Anaconda 2.1.0 (x86_64)
anaconda3-2.1.0every time you visit a particular project directory, say
# unset the shell specific version pyenv shell --unset # go to the project directory cd ~/project pyenv local anaconda3-2.1.0 # check python version python -V # Python 3.4.1 :: Anaconda 2.1.0 (x86_64)
Note: you run
python -V outside
project, you will see the system python.
pyenv global anaconda3-2.1.0. But I don’t recommend this.
If you really don’t like
pyenv and want to remove all traces of
pyenv files. Just remove
pyenv from homebrew and remove the
~/.pyenv directory. It will do the job. Of course, you have to also undo the changes made to the