MacOS 13.1下Pyenv安装Python 3.6.0失败求助
解决Pyenv安装Python 3.6.0失败的问题
核心原因
Python 3.6.0属于老旧版本,与MacOS 13.1(Ventura)的新编译器工具链不兼容;同时你的python-build版本(20180424)过于陈旧,缺乏对新系统的适配支持,导致出现找不到clang++、平台triplet配置错误的问题。
分步解决方案
1. 更新Pyenv至最新版本
旧版Pyenv对新MacOS系统兼容性差,先完成更新:
- 若通过源码安装Pyenv:
cd $(pyenv root) git pull
- 若通过Homebrew安装Pyenv:
brew update && brew upgrade pyenv
2. 明确指定编译器路径与兼容SDK
Python 3.6.0需要强制指定clang++的完整路径,同时搭配系统存在的SDK版本执行安装:
- 先查看本地可用的MacOS SDK:
ls /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
- 替换下面命令中的
MacOSX13.sdk为你实际存在的SDK版本,执行安装:
SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.sdk \ MACOSX_DEPLOYMENT_TARGET=10.15 \ CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ \ pyenv install 3.6.0
3. 应用补丁适配新系统
若上述步骤仍失败,给Python 3.6.0打补丁修复平台triplet检测逻辑:
- 创建补丁文件
python360-ventura.patch,内容如下:
diff --git a/configure b/configure index 0d5a3a2..f3e08a9 100755 --- a/configure +++ b/configure @@ -13105,12 +13105,10 @@ then esac fi elif test "$ac_sys_system" = "Darwin"; then - AC_MSG_CHECKING(for the platform triplet based on compiler characteristics) - if test -z "$GCC"; then - ac_platform_triple="$host" - else - ac_platform_triple=`$GCC -dumpmachine` - fi + # Skip platform triplet detection for new macOS versions + ac_platform_triple="x86_64-apple-darwin" AC_MSG_RESULT($ac_platform_triple) else AC_MSG_CHECKING(for the platform triplet based on compiler characteristics)
- 执行带补丁的安装命令:
SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.sdk \ MACOSX_DEPLOYMENT_TARGET=10.15 \ CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ \ pyenv install 3.6.0 --patch < python360-ventura.patch
4. 备选方案:Docker容器环境
如果本地环境适配困难,直接用Docker运行Python 3.6.0容器,规避系统兼容问题:
docker run -it python:3.6.0 bash
在容器内正常安装OpenCV即可。
内容的提问来源于stack exchange,提问作者Carrie Chen
相关产品推荐
相关产品推荐

