如何在MacOS 12.3&#x2B上安装Python 2
macOS 12.3 更新删除了 Python 2 并将其替换为版本 3:
https://developer.apple.com/documentation/macos-release-notes/macos-12_3-release-notes
Python 弃用 在此更新中,Python 2.7 已从 macOS 中删除。开发人员应该使用 Python 3 或替代语言。 (39795874)
我知道我们需要迁移到版本 3,但与此同时我们仍然需要版本 2。Homebrew 似乎不再拥有它:
brew install [email protected]
Warning: No available formula with the name "[email protected]". Did you mean [email protected], [email protected], [email protected], [email protected] or python-yq?
brew install python2
Warning: No available formula with the name "python2". Did you mean ipython, bpython, jython or cython?
什么提供了?
macOS 12.3 update drops Python 2 and replaces it with version 3:
https://developer.apple.com/documentation/macos-release-notes/macos-12_3-release-notes
Python
Deprecations
Python 2.7 was removed from macOS in this update. Developers should use Python 3 or an alternative language instead. (39795874)
I understand we need to migrate to version 3, but in the meantime we still need version 2. Homebrew does not seem to have it anymore:
brew install [email protected]
Warning: No available formula with the name "[email protected]". Did you mean [email protected], [email protected], [email protected], [email protected] or python-yq?
brew install python2
Warning: No available formula with the name "python2". Did you mean ipython, bpython, jython or cython?
What gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以从官方下载站点中获取任何Python发行版,包括最后一个Python 2:
https ://www.python.org/downloads/release/python-2718/ → macOS 64位安装程序
You can get any Python release, including the last Python 2, from the official download site:
https://www.python.org/downloads/release/python-2718/ → macOS 64-bit installer
如果像我一样,您需要它进行开发,您应该使用 PyEnv:
这是一个很棒的教程:
https://dev.to /jordicuevas/how-to-install-python2-in-a-macbook-m1-with-brew-bhi
TL;DR:
(按照提供的说明进行操作。我必须添加到
~/.zprofile
和~/.zshrc
。)确保通过运行
source ~/.zprofile
和source 加载更改~/.zshrc
。现在,
python
命令应该以 shell/终端中的 Python 2 为目标。If, like me, you need it for development you should use PyEnv:
Here's a great tutorial:
https://dev.to/jordicuevas/how-to-install-python2-in-a-macbook-m1-with-brew-bhi
TL;DR:
(Follow instructions provided. I had to add to
~/.zprofile
and~/.zshrc
.)Make sure you load the changes by running
source ~/.zprofile
andsource ~/.zshrc
.Now, the
python
command should target Python 2 in the shell/Terminal.更多相关信息。由于 macOS 删除了支持 python2,并且有一个未解决的问题来删除所有这python2 公式也是如此。
我建议不要使用 python 官方安装程序,而是使用 pyenv,这样可以更轻松地管理您的多个 python 版本当地的。
A bit more relevant information. It was removed due to the fact that macOS remove the support of python2, and there is an open issue to remove all the python2 formulae as well.
Instead of using python official installer, I would suggest using pyenv, which is easier to manage multiple python versions in your local.