How to install and switch versions of Python using pyenv. Even if there is a standard installation or a brew installation, it can coexist (switch) without any problem in principle.
Installation can be done with brew, so use brew.
brew install pyenv
Set environment variables. It's OK if ~ / .pyenv is viewed in preference to all PATHs (if it is / usr / bin or / usr / local / bin, the existing Python will be prioritized).
export PYENV_ROOT="${HOME}/.pyenv"
export PATH=${PYENV_ROOT}/bin:$PATH
eval "$(pyenv init -)"
Reflect the variable.
source .bash_profile
Let's take a look at the list of versions that can be set with pyenv.
pyenv install -l
Install the version of your choice. I often use it in the calculation system, so I install the 2.x system of anaconda.
pyenv install anaconda-2.4.0
Get a list of installed versions. In this state, it is not yet available (PATH is not available).
pyenv versions
To actually use the specified version, specify the version with the global command.
pyenv global anaconda-2.4.0
If you want to apply only in a specific directory, there is also an option called local. By using local, .python-version is created under the working directory, the version is set, and that setting has priority over global.
After changing the version etc., we will update various information to make it work properly.
pyenv rehash
It seems that this operation can be automated by installing brew install pyenv-pip-rehash. It seems that you need to do brew install homebrew / boneyard / pyenv-pip-rehash at the time of installation.
The original one is treated as a system.
pyenv versions
* system (set by /Users/user/.pyenv/version)
anaconda-2.4.0
Because it seems to be
pyenv global system
(However, it seems that even if you do which, it does not become / usr / bin etc.).
Naturally, it seems that installation and management with pip is also done for each version.
Recommended Posts