目录
安装 Python2
MAC 系统已经默认带有 Python2.7 了,所以无需安装它。
安装 Python3
brew install python3
不同版本Python路径
MAC 系统自带 Python2.7,而我们安装 Python3 的时候,可以通过 brew 命令安装或者官网的 pkg 安装。安装后,它们的文件保存路径如下:
- 系统默认(2.7):/System/Library/Frameworks/Python.framework/Versions/2.7
- brew安装(2.7/3.x):/usr/local/Cellar/python
- 官网pkg安装(3.x):/Library/Frameworks/Python.framework/Versions/3.x
配置 Python2 和 Python3
vi ~/.bash_profile
# Setting PATH for Python 2.7
PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
# Setting PATH for Python 3.6.5
PATH="/usr/local/Cellar/python/3.6.5/bin:${PATH}"
export PATH
vi ~/.bashrc
alias python2='/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'
alias python3='/usr/local/Cellar/python/3.6.5/bin/python3.6'