mac安装Python2和Python3

如何在mac安装Python2和Python3两个版本,步骤如下:

因为我的mac默认已经安装了python2,就不再安装python2

mac安装Python2和Python3_第1张图片
在安装前确认homebrew是可以用的,我直接使用Homebrew安装:brew install python3
mac安装Python2和Python3_第2张图片
打开/usr/local/Cellar/python
mac安装Python2和Python3_第3张图片
使用homebrew安装成功以后的默认路径在:/usr/local/Cellar/python/
mac安装Python2和Python3_第4张图片
设定$PATH路径和系统自带python2区分开,互不影响

# Python 2.7

PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

#  Python3.7.3

PATH="/usr/local/Cellar/python/3.7.3/bin:${PATH}"

export PATH

source ~/.profile

设置别名:

alias python2='/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'

alias python3='/usr/local/Cellar/python/3.7.3/bin/python3.7'

设置完成记得需要source让配置文件生效。

mac安装Python2和Python3_第5张图片
输入:python3
mac安装Python2和Python3_第6张图片
输入:python和python2
mac安装Python2和Python3_第7张图片
结束!

你可能感兴趣的:(mac安装Python2和Python3)