brew安装python2
source link: https://www.wyr.me/post/658
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Homebrew是MacOS中绝佳的包管理工具。通过brew安装pyton3非常容易brew install python@3
,将会自动添加python3
和pip3
命令。
关于python的安装,在Homebrew
官网给出了详细的说明:https://docs.brew.sh/Homebrew-and-Python
Homebrew provided a
python@2
formula until the end of 2019, at which point it was removed due to the Python 2 deprecation.
根据提示,我们知道python@2
已经被移除。在2020年初,python@2
仍然可以正常安装,但就在不久前,官方移除了python@2
。我对Homebrew
官方的操作表示支持和理解,毕竟技术的更新和迭代是不可逆转的,是需要大家一起支持的。
Python官方宣布 2020 年 1 月后不再更新维护 Python2,然而由于历史原因以及各国生态差异,某些情况下不得不再次安装python2
。即使距离python3最初版本发布已经超过10年,仍然有很多项目依赖python2(这里没有吐槽的意思,但JavaScript生态必须感谢babel
)。
brew安装python2的方式:
cd ~
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/86a44a0a552c673a05f11018459c9f5faae3becc/Formula/[email protected]
brew install [email protected]
rm [email protected]
安装python2是不被推荐的。
- 通过
brew extract
安装python2
的方式已经失效了,参见。 - 上述安装方法参考自:https://stackoverflow.com/questions/60298514/how-to-reinstall-python2-from-homebrew
- 在M1芯片的Mac设备上,此安装方式不适用于原生支持 ARM 架构的Homebrew实验性版本。需要安装
Rosetta
加持的X86版本Homebrew,然后使用上述方法进行安装。 - 如果上述
wget
命令执行失败,有可能是网络原因导致的。可以考虑使用 https://cdn.wyr.me/files/2021-02-03/[email protected] 地址代替。
M1芯片使用Intel版本Homebrew
For what it's worth, before installing Homebrew you will need to install Rosetta2 emulator for the new ARM silicon (M1 chip). I just installed Rosetta2 via terminal using:
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
This will install rosetta2 with no extra button clicks.
After installing Rosetta2 above you can then use the Homebrew cmd and install Homebrew for ARM M1 chip:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Once Homebrew for M1 ARM is installed use this Homebrew command to install packages:
arch -x86_64 brew install <package>
从MacOS 12.3 Beta版本开始,Apple不再内置python2且将无法正常安装python2,无论是intel芯片还是Apple芯片的设备都无法安装。原因是/usr/bin/python
的软链接无法正常被删除或覆盖。
2022年04月17日14:02:24更新: 从MacOS 12.4 Beta版(21F5048e) 开始,可以通过pyenv
在intel和Apple芯片中安装python2。
例如在M1中安装 2.7.18 版本的 python2。
brew install pyenv
pyenv install 2.7.18
export PATH="$(pyenv root)/shims:${PATH}"
pyenv global 2.7.18
python --version
如果一切顺利,将可以看到Python 2.8.18
的输出。
需要将上述路径添加到环境变量里面,例如:
echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc
此方法可以与brew install python3
方式安装的python3
共存。
如果遇到VS(Visual Studio Code)无法使用code
命令,可以参阅博文:《MacOS 12.3 无法正常使用code命令的解决方法》。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK