You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac M1编译Python 3.7.3源码时遭遇平台三元组配置错误

在Mac M1上编译Python 3.7.3时的平台三元组配置错误解决

问题背景

在Mac M1上通过源码编译Python 3.7.3,执行configure命令时遇到internal configure error for the platform triplet错误,即使显式指定CXX环境变量也无法解决。

具体报错及环境信息

初始配置命令及报错

执行:

./configure --enable-shared --with-openssl=/usr/local/opt/openssl/ --prefix=path_to_install

(已替换path_to_install为实际安装路径)
报错输出:

checking build system type... x86_64-apple-darwin21.6.0
checking host system type... x86_64-apple-darwin21.6.0
checking for python3.7... python3.7
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for a sed that does not truncate output... /usr/bin/sed
checking for --with-cxx-main=<compiler>... no
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.
  
checking for the platform triplet based on compiler characteristics... darwin
configure: error: internal configure error for the platform triplet, please file a bug report

指定CXX后的报错

执行:

CXX=/Library/Developer/CommandLineTools/usr/bin/g++ ./configure --enable-shared --with-openssl=/usr/local/opt/openssl/ --prefix=/Users/fryderykkogl/python_for_imfusion

或

CXX=/usr/bin/g++ ./configure --enable-shared --with-openssl=/usr/local/opt/openssl/ --prefix=/Users/fryderykkogl/python_for_imfusion

仍报错:

checking build system type... arm-apple-darwin21.6.0
checking host system type... arm-apple-darwin21.6.0
checking for python3.7... python3.7
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for a sed that does not truncate output... /usr/bin/sed
checking for --with-cxx-main=<compiler>... no
checking for the platform triplet based on compiler characteristics... darwin
configure: error: internal configure error for the platform triplet, please file a bug report

当前环境信息

g++ --version返回:

Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

which g++返回:

/usr/bin/g++

解决方法

Python 3.7.3发布时Apple Silicon(M1)尚未推出,因此原生不支持ARM架构编译,这是报错的核心原因。推荐以下两种可行方案:

1. 通过Rosetta 2以x86_64架构编译

  • 切换终端到x86_64模式:
arch -x86_64 zsh
  • 确保依赖(如openssl)以x86_64架构安装:
arch -x86_64 brew install openssl
  • 重新执行configure命令:
./configure --enable-shared --with-openssl=/usr/local/opt/openssl/ --prefix=/Users/fryderykkogl/python_for_imfusion
  • 完成编译安装:
make -j4
make install

2. 使用pyenv安装(更简便可靠)

pyenv已适配M1架构,可直接安装指定版本:

  • 安装pyenv:
brew install pyenv
  • 安装Python 3.7.3:
pyenv install 3.7.3
  • 设置全局或局部使用该版本:
pyenv global 3.7.3  # 全局生效
# 或
pyenv local 3.7.3   # 当前目录生效

3. 手动打补丁(不推荐)

若坚持原生ARM编译,需寻找针对Python 3.7的Apple Silicon适配补丁修改源码,但过程复杂且易出现其他兼容性问题,仅适合有经验的开发者。

内容的提问来源于stack exchange,提问作者koegl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 10:50:30