使用 M1 芯片(基于 ARM 的 Apple Silicon)在 Mac 上安装早期版本的 Python(3.8 之前)失败

Installation of earlier versions of Python (prior to 3.8) fails on Mac with M1 Chip (ARM based Apple Silicon)

我有 MacApple M1 芯片的书,其中我的项目必须使用 Python 3.6.5。它预装了 Python 2.7.16 和 3.8.2。我使用 brew 安装 Python,默认安装 3.9.1.

所以,我尝试 this 自制程序安装 3.6.5,但出现以下错误:

checking for pthread_t... yes
checking size of pthread_t... 8
configure: error: Unexpected output of 'arch' on OSX

Do not report this issue to Homebrew/brew or Homebrew/core!

我试过 pyenv install 3.6.5 ,但失败并出现与上述类似的错误。 ePi272314 解释 的方法以 git 提交安装 python 失败,因为自制程序不再支持它。

当我尝试 运行ning Terminal with Rosetta 2 并安装 python 3.6.5 时,使用上述方法,我得到以下或一些其他编译错误:

Error: Cannot install in Homebrew under Rosetta 2 in ARM default prefix (/opt/homebrew)!

最后,我下载了Python3.6.5的dmg文件并安装了。它安装正常,在 /usr/local/bin/python3 上作为 python3 安装可见,但不能 运行.

kxxxr@Kxxxns-MBP bin % where python3
/opt/homebrew/bin/python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
/opt/homebrew/bin/python3
/usr/local/bin/python3
/usr/bin/python3
kxxxr@Kxxxns-MBP bin % /opt/homebrew/bin/python3 --version
Python 3.9.1
kxxxr@Kxxxns-MBP bin % /usr/local/bin/python3 --version
zsh: killed     /usr/local/bin/python3 --version
kxxxr@Kxxxns-MBP bin % 

由 Python dmg 文件安装的闲置文件也不能 运行(我有管理员权限)。

最后遇到了 this python 错误报告,其中说错误正在为 Python 3.8、3.9 和 3.10 修复。很明显,M1 芯片官方似乎不支持旧版本。

我的问题是:

  1. 有没有其他方法可以在 Mac M1 上使用 Python 3.6.5?我错过了什么吗?
  2. 如果没有,请提及。我会接受这个作为答案。

提前致谢。

使用@Charles Duffy 的回答,您可以在 M1s 上制作旧版本 运行。 但是 Python 3.8 之前的版本将不会在 M1 上得到正式支持,因为在 M1 芯片发布时它们不在错误修复阶段。明确表示 here 为:

">是否有计划将 PR 22855 反向移植到 3.9 之前的任何分支?

计划还支持 Big Sur 和 Apple Silicon 上的 3.8,因为 3.8 仍处于错误修复模式。没有计划向后移植支持 3.7 和 3.6,它们处于发布周期的仅安全修复阶段。"

this python 错误跟踪器中。

所以我认为没有任何方法可以让他们在 M1 上工作,除非有人自己调整 python。

Nix 安装在 Rosetta 2 下就可以了。在下面 运行 之前我什至没有安装它——请注意显示 Nix 在我请求时正在下载 Python 3.6 的消息。

# yes, this really is a M1 Mac
charles@macbook-pro ~ % uname -a
Darwin macbook-pro.lan 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec  2 20:40:21 PST 2020; root:xnu-7195.60.75~1/RELEASE_ARM64_T8101 x86_64 i386 MacBookPro17,1 Darwin
charles@macbook-pro ~ % arch
arm64

# ...however, Rosetta was used to install an x86_64 Nix build
charles@macbook-pro ~ % file "$(realpath "$(command -v nix)")"
/nix/store/104sp9zrhmh3jycj32jcyl3f13mysdki-nix-2.3.9/bin/nix: Mach-O 64-bit executable x86_64

# ...and that x86_64 Nix build can install and run an x86_64 Python 3.6
charles@macbook-pro ~ % nix run nixpkgs.python36 -c python
[1 copied (53.7 MiB), 9.3 MiB DL]
Python 3.6.12 (default, Dec 18 2020, 15:32:50) 
[GCC 4.2.1 Compatible Clang 7.1.0 (tags/RELEASE_710/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

以上内容(出于可重复性目的)是通过 nixpkgs 收集的,指的是频道 https://nixos.org/channels/nixpkgs-20.09-darwin,特别是实例 sn5ycj9wkbdmyinvqyg9rn42sw71wqad-nixpkgs-20.09pre245572.f18fbc33930

Python M1 不支持 3.6 可能是因为 3.6 将在今年年底 (2021) 到达行尾 (EOL)。

我建议您在 M1 上至少尝试 Python 3.7 或更高版本。使用 pyenv,我已成功在 macOS 11 (Apple Silicon) 上本地安装 Python 3.7.103.8.63.9.4。如果您仍在寻找答案,本文将帮助您完成整个过程:https://squademy.medium.com/install-python-on-macos-11-m1-apple-silicon-using-pyenv-12e0729427a9

虽然是 EOL,但您可以使用 pyenv 在 Mac M1 上安装最终版本 3.6.15。

我能够从源安装 3.8:

./configure --enable-framework=/Users/MyUName/lib/Frameworks
make && make install

我试过 3.7,但它在制作过程中死了:

cd Mac && /Applications/Xcode.app/Contents/Developer/usr/bin/make pythonw
gcc  -DPYTHONFRAMEWORK='"Python"' -o pythonw \
        ./Tools/pythonw.c -I.. -I./../Include \
        ../Python.framework/Versions/3.7/Python
./Tools/pythonw.c:125:9: error: "Unknown CPU"
#       error "Unknown CPU"
        ^

我试过 3.6,它在配置过程中死机了:

checking for g++... no
configure:

  By default, distutils will build C++ extension modules with "g++".
  If this is not intended, then set CXX on the configure command line.

所以我尝试添加 CXX=$(xcode-select -p)/usr/bin/g+ 但它并没有得到更多:

checking for the platform triplet based on compiler characteristics... darwin
configure: error: internal configure error for the platform triplet, please file a bug report

Conda 甚至不支持 M1 的 3.6 和 3.7。