MAC 系统自带python2,升级到python3的操作:
brew install python
brew upgrade python
安装结束后会有下面提示:
If you need to have python@3.8 first in your PATH, run:
echo 'export PATH="/usr/local/opt/python@3.8/bin:$PATH"' >> ~/.zshrc
For compilers to find python@3.8 you may need to set:
export LDFLAGS="-L/usr/local/opt/python@3.8/lib"
For pkg-config to find python@3.8 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/python@3.8/lib/pkgconfig"
将这三个环境变量和 alias python='python3'
配置到 ~/.bash_profile
source ~/.bash_profile
同时配置~/.zshrc
if [ -f ~/.bash_profile ]; then
source ~/.bash_profile
fi
export PATH=/usr/local/opt/python@3.8/bin:$PATH
python --version 验证为结果