Manage Python using a Python version manager called pyenv. If you're on a Mac, Python is already installed, but I don't want to use it because it's for the system. Of course, you can easily install it using Homebrew, but if you want to switch between multiple versions of Python, it is realistic to use the version manager.
Clone pyenv to .pyenv
in your home directory.
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
For zsh, like .zshrc
. For bash, like .bash_profile
.
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
In other words, it is OK if the following settings are described.
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
After restarting the shell, you can use the pyenv
command.
Install Python by specifying the version as follows.
$ pyenv install 3.4.3
$ pyenv install 2.7.9
Then, the installed Python will be placed under ~ / .pyenv / versions /
. After installing, refresh shim.
$ pyenv rehash
After that, specify the Python to actually use. If you want to specify it globally, use pyenv global
. If you want to specify it locally, use pyenv local
.
$ pyenv global 3.4.3
After execution, it is OK if the path points to python under .pyenv
. In the case of pyenv local
, a file called .python-version
will be created in the current directory, and the specified version of Python will be referenced there.
$ which python
# /Users/1000ch/.pyenv/shims/python
Uninstall Python installed using pyenv
as follows.
$ pyenv uninstall 3.4.3
It is as it is.
Recommended Posts