一、mac自带的一个2.7版本的python,在终端查看版本 python --version
二、安装 python3
1.安装homebrew
在终端执行 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.安装python3
在终端执行 brew install python
执行完之后,可以在 /usr/local/Cellar/python 看到python安装的版本
系统预装的目录在 /usr/bin/
3.设置环境变量
a、终端执行 sudo vim /etc/profile (记着用sudo,否则没有修改权限!)
b、添加如下内容:
export PATH=${PATH}:/usr/local/Cellar/python/3.7.4/bin
alias python="/usr/local/Cellar/python/3.7.4/bin/python3"
alias pip="/usr/local/Cellar/python/3.7.4/bin/pip3"
注意:我这里安装的是3.7.4版本,你需要查看 /usr/local/Cellar/python 目录下自己安装的版本并修改
c、退出的时候命令是 wq!,切记是wq!,不是!wq
d、刷新环境变量,终端执行:source /etc/profile
4.查看版本
终端执行 python --version
如果正常此时应该是 Python 3.7.4
5.每次打开新的终端,输入 python --version 还是显示Python 2.7,需要source /etc/profile才行
莫慌~
在 ~/.zshrc 最后增加:
source ~/.bash_profile
source /etc/profile