Installing Homebrew
Use Homebrew to manage Python versions. In Terminal/iterm2 input:
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
If the previous system did not install Command line Tools, this time will also be automatically prompted to install, as prompted to do so; For more details on the Homebrew settings, refer to the previous article;
Installing Python 3.4 with Homebrew
$ brew tap homebrew/science$ brew tap homebrew/python$ brew update && brew upgrade# 安装 brewed python3$ brew install python3
Check the path:
$ which python3# 应该提示 /usr/local/bin/python3$ echo $PATH# /usr/local/bin 需要在 /usr/bin 之前
Install PIL, etc.
$ brew install pillow imagemagick graphviz$ brew install cairo --without-x$ brew install py2cairo # 如果系统里没有 xquartz,需要先自行安装:https://xquartz.macosforge.org/landing/$ brew install qt pyqt
Install Numpy, Scipy, etc.
Python 3.4 starts with a built-in PIP Package Manager that enables pip3
you to manage the required packages directly using commands:
pip3 install numpypip3 install scipypip3 install matplotlibpip3 install pandaspip3 install ipython[all]
Set commands such as Python/ipython/pip to use the Python 3.X version by default
If there are two versions of 2.7.X and 3.X in the system, the python
ipython
pip
command will use the 2.7.X version by default. To use the 3.X version, either use the command, python3
ipython3
pip3
or add the alias in the. Bash_profile:
$ subl .bash_profile # 使用 sublime text 打开 .bash_profile 文件
Add in File:
# aliasalias python=python3alias ipython=ipython3alias pip=pip3
After setting,, and python
ipython
so on, the pip
command will load the 3.X version by default, to use the 2.7.X version, then enter python2
, ipython2
pip2
.
Why use Python 3.X
Would scientists ever Move to Python 3?
Why do you should move to Python 3-now
Reference
Scientific Python on Mac OS X 10.9 with homebrew
Build Python3 scientific computing environment in MAC OS X 10.9