There are some things to prepare before installing Python.
Homebrew
Install Homebrew.
Since ruby is installed on MacOS, execute the following command from the terminal.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Let's check the installation destination.
$ which brew
/usr/local/bin/brew
To update Homebrew, run the following command. $ brew update && brew upgrade
pyenv
Then install Pyenv. This is Python version control software.
Normally, Python 2.7 is already installed on MacOS, but if you want to use multiple versions of Python, use this software.
$ brew install pyenv
Then edit the .bash_profile in your home directory.
Edit with vi or
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
Write to .bash_profile as follows.
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
afterwards,
$ source .bash_profile
Refresh with.
Now you're ready to install Python. Now let's actually install it. You can check the list of installable Python with the following command.
$ pyenv install -l
Available versions:
2.1.3
2.2.3
2.3.7
Install a specific version. $ pyenv install 3.5.1
Check the installed version.
$ pyenv versions
* system (set by /Users/yoshi/.pyenv/version)
3.5.1
To select the version you actually want to activate
$ pyenv global 3.5.1
will do. When I check it,
$ pyenv versions
system
* 3.5.1 (set by /Users/yoshi/.pyenv/version)
like*The mark has been changed.
You have now installed the 3.5.1 version.
Let's check.
$ which python
/Users/username/.pyenv/shims/python
It is installed in .pyenv in your home directory.
Let's actually start it.
$ python
Python 3.5.1 (default, Jul 5 2016, 01:34:21)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
\>>>
Recommended Posts