在操作系统 12.3+ 的新 macbook pro M1 上使用 pyenv 安装 python 3.7.6 时出错

Tir*_*Das 5 python macos pyenv apple-m1

我正在努力使用 pyenv 在运行 mac os 12.3.1 的新 macbook pro M1 上安装 python 版本 3.7.6。

我的配置

$ clang -v
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Run Code Online (Sandbox Code Playgroud)
$ pyenv install 3.7.6

python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.6.tar.xz...
-> https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz
Installing Python-3.7.6...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 12.3.1 using python-build 2.2.5-10-g58427b9a)

Inspect or clean up the working tree at /var/folders/4t/1qfwng092qz2qxwxm6ss2f1c0000gp/T/python-build.20220405170233.32567
Results logged to /var/folders/4t/1qfwng092qz2qxwxm6ss2f1c0000gp/T/python-build.20220405170233.32567.log

Last 10 log lines:
checking for --with-cxx-main=<compiler>... no
checking for clang++... no
configure:

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

checking for the platform triplet based on compiler characteristics... darwin
configure: error: internal configure error for the platform triplet, please file a bug report
Run Code Online (Sandbox Code Playgroud)

Tir*_*Das 2

最后,这个补丁可以使用 pyenv 在 macbook m1 上安装 3.7.6。

要使用 pyenv 在 mac os 12+、M1 芯片、apple clang 版本 13+ 中安装 python 3.7.6 版本,请在本地任意位置创建一个文件,并将其命名为 python-3.7.6-m1.patch 并复制内容(如下)到该文件并保存它。

diff --git a/configure b/configure
index b769d59629..8b018b6fe8 100755
--- a/configure
+++ b/configure
@@ -3370,7 +3370,7 @@ $as_echo "#define _BSD_SOURCE 1" >>confdefs.h
   # has no effect, don't bother defining them
   Darwin/[6789].*)
     define_xopen_source=no;;
-  Darwin/1[0-9].*)
+  Darwin/[12][0-9].*)
     define_xopen_source=no;;
   # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but
   # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined
@@ -5179,8 +5179,6 @@ $as_echo "$as_me:
 fi
 
 
-MULTIARCH=$($CC --print-multiarch 2>/dev/null)
-
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the platform triplet based on compiler characteristics" >&5
 $as_echo_n "checking for the platform triplet based on compiler characteristics... " >&6; }
@@ -5338,6 +5336,11 @@ $as_echo "none" >&6; }
 fi
 rm -f conftest.c conftest.out
 
+if test x$PLATFORM_TRIPLET != xdarwin; then
+  MULTIARCH=$($CC --print-multiarch 2>/dev/null)
+fi
+
+
 if test x$PLATFORM_TRIPLET != x && test x$MULTIARCH != x; then
   if test x$PLATFORM_TRIPLET != x$MULTIARCH; then
     as_fn_error $? "internal configure error for the platform triplet, please file a bug report" "$LINENO" 5
@@ -9247,6 +9250,9 @@ fi
      ppc)
        MACOSX_DEFAULT_ARCH="ppc64"
        ;;
+     arm64)
+        MACOSX_DEFAULT_ARCH="arm64"
+       ;;
      *)
        as_fn_error $? "Unexpected output of 'arch' on OSX" "$LINENO" 5
        ;;
diff --git a/configure.ac b/configure.ac
index 49acff3136..2f66184b26 100644
--- a/configure.ac
+++ b/configure.ac
@@ -490,7 +490,7 @@ case $ac_sys_system/$ac_sys_release in
   # has no effect, don't bother defining them
   Darwin/@<:@6789@:>@.*)
     define_xopen_source=no;;
-  Darwin/1@<:@0-9@:>@.*)
+  Darwin/@<:@[12]@:>@@<:@0-9@:>@.*)
     define_xopen_source=no;;
   # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but
   # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined
@@ -724,8 +724,7 @@ then
 fi
 
 
-MULTIARCH=$($CC --print-multiarch 2>/dev/null)
-AC_SUBST(MULTIARCH)
+
 
 AC_MSG_CHECKING([for the platform triplet based on compiler characteristics])
 cat >> conftest.c <<EOF
@@ -880,6 +879,11 @@ else
 fi
 rm -f conftest.c conftest.out
 
+if test x$PLATFORM_TRIPLET != xdarwin; then
+  MULTIARCH=$($CC --print-multiarch 2>/dev/null)
+fi
+AC_SUBST(MULTIARCH)
+
 if test x$PLATFORM_TRIPLET != x && test x$MULTIARCH != x; then
   if test x$PLATFORM_TRIPLET != x$MULTIARCH; then
     AC_MSG_ERROR([internal configure error for the platform triplet, please file a bug report])
Run Code Online (Sandbox Code Playgroud)

现在我们可以使用 pyenv 安装 python 3.7.6,如下所示(需要与我们刚刚创建的补丁文件位于同一目录中):

pyenv install --patch 3.7.6 < python-3.7.6-m1.patch
Run Code Online (Sandbox Code Playgroud)

使用 pyenv 在 mac os 12+、M1 芯片、apple clang 版本 13+ 上安装其他 python 版本(未经测试,但应该可以工作)

浅克隆您有兴趣安装的 python 版本的分支。转到https://github.com/python/cpython 并在“标签”下拉列表中找到可用于克隆的版本

git clone https://github.com/python/cpython --branch v3.x.x --single-branch
cd cpython
Run Code Online (Sandbox Code Playgroud)

现在更改其中的两个文件(configure.ac 和 configure)。git diff 应该如上所示。根据您安装的 python 版本,行号会有所不同,此 git diff 文件适用于 3.7.6,不能直接用于其他版本。对于其他版本的 python,请在上面的 git diff 所示的确切文件中搜索正在编辑/删除的确切代码行,并进行相应的更改。然后将 git diff 保存在新文件中,如下所示。

git diff > python-3.x.x-m1.patch
Run Code Online (Sandbox Code Playgroud)

现在我们可以使用以下命令安装该版本:

pyenv install --patch 3.x.x < python-3.x.x-m1.patch
Run Code Online (Sandbox Code Playgroud)

  • 感谢您的回答。它对我不起作用。输出: pyenv install --patch 3.7.6 &lt; python-3.7.6-m1.patch python-build:使用自制程序中的 openssl@1.1 python-build:使用自制程序中的 readline 正在下载 Python-3.7.6.tar.xz.. . -&gt; https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz 正在安装 Python-3.7.6... 修补文件配置 Hunk #4 在 9250.1 处失败4 个大块头失败 - 保存拒绝文件configure.rej 修补文件configure.ac 构建失败(OS X 12.0.1 使用 python-build 20180424) (4认同)