如何在MacOS 12.3&#x2B上安装Python 2

发布于 2025-01-19 06:38:59 字数 1464 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

趴在窗边数星星i 2025-01-26 06:38:59

您可以从官方下载站点中获取任何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

智商已欠费 2025-01-26 06:38:59

如果像我一样,您需要它进行开发,您应该使用 PyEnv:

这是一个很棒的教程:
https://dev.to /jordicuevas/how-to-install-python2-in-a-macbook-m1-with-brew-bhi

TL;DR:

brew install pyenv
pyenv install 2.7.18
export PATH="$(pyenv root)/shims:${PATH}"
echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc
pyenv init

(按照提供的说明进行操作。我必须添加到~/.zprofile~/.zshrc。)

确保通过运行 source ~/.zprofilesource 加载更改~/.zshrc

pyenv shell 2.7.18

现在,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:

brew install pyenv
pyenv install 2.7.18
export PATH="$(pyenv root)/shims:${PATH}"
echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc
pyenv init

(Follow instructions provided. I had to add to ~/.zprofile and ~/.zshrc.)

Make sure you load the changes by running source ~/.zprofile and source ~/.zshrc.

pyenv shell 2.7.18

Now, the python command should target Python 2 in the shell/Terminal.

半世蒼涼 2025-01-26 06:38:59

更多相关信息。由于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文