macOS M1芯片下使用Homebrew管理多个Python版本安装记录
一、安装Homebrew(如果还未安装)
正常安装版(慢)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"确保你的PATH中已加入/opt/homebrew/bin,可以执行:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc二、安装Python多个版本
1. 安装Python 3.10
brew install python@3.10
# 输出确认安装路径
brew --prefix python@3.10示例输出:
/opt/homebrew/opt/python@3.102. 安装Python 3.12
brew install python@3.12
brew --prefix python@3.12示例输出:
/opt/homebrew/opt/python@3.12三、确认安装内容
ls /opt/homebrew/opt/python@3.10/bin/
# 应看到有:python3.10、pip3.10等四、设置别名方便调用
编辑你的 ~/.zshrc,添加:
# Python 3.10
alias python3.10="/opt/homebrew/opt/python@3.10/bin/python3.10"
# Python 3.12
alias python3.12="/opt/homebrew/opt/python@3.12/bin/python3.12"保存后,执行:
source ~/.zshrc五、切换版本(示例)
切换到 Python 3.10:
python3.10 --version切换到 Python 3.12:
python3.12 --version六、用brew link方式管理(可选)
如果想让python3指向某个版本:
# 切换到 Python 3.10
brew unlink python@3.12
brew link --force --overwrite python@3.10
# 切换到 Python 3.12
brew unlink python@3.10
brew link --force --overwrite python@3.12七、总结
- 安装路径:
- Python 3.10:python@3.10"">`/opt/homebrew/opt/python@3.10/bin/python3.10`
- Python 3.12:python@3.12"">`/opt/homebrew/opt/python@3.12/bin/python3.12`
- 管理方式:用
alias快速调用 - 版本切换:用
brew unlink和brew link
作者:admin 创建时间:2025-10-24 22:17
最后编辑:admin 更新时间:2025-10-24 22:21
最后编辑:admin 更新时间:2025-10-24 22:21