一,查看老版本的python信息:
1,启动终端,查看旧的python的版本
liuhongdi@192 ~ % python --version
Python 3.9.1
2,查看旧的pytnon的安装路径
liuhongdi@192 ~ % which python
python: aliased to /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9
二,编辑.zprofile,配置环境变量
1,查看:
可以看到两种设置,分别针对3.9和我们新安装的3.12
liuhongdi@192 ~ % more .zprofile
# Setting PATH for Python 3.9
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
export PATH
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
alias python="/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9"
alias pip="/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9"
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles #ckbrew
eval $(/usr/local/Homebrew/bin/brew shellenv) #ckbrew
# Setting PATH for Python 3.12
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.12/bin:${PATH}"
export PATH
2,编辑
把原3.9的命令删除或注释掉,
在3.12的export PATH下面添加两行alias,如下:
# Setting PATH for Python 3.12
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.12/bin:${PATH}"
export PATH
alias python="/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12"
alias pip="/Library/Frameworks/Python.framework/Versions/3.12/bin/pip3.12"
3,使生效:
liuhongdi@192 ~ % source .zprofile
三,测试效果
liuhongdi@192 ~ % python --version
Python 3.12.0
标签:bin,macos,python,3.12,Python,PATH,3.9
From: https://www.cnblogs.com/architectforest/p/17835428.html