在Mac OS 15.5上使用pyenv安装Python 3.7.7失败求助
在Mac OS 15.5上使用pyenv安装Python 3.7.7失败求助
我的问题
我在MacBook Pro(系统版本15.5)上用pyenv install 3.7.7安装Python 3.7.7时一直失败,具体的错误输出如下:
pyenv install 3.7.7 python-build: use openssl from homebrew python-build: use readline from homebrew Downloading Python-3.7.7.tar.xz... -> https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tar.xz Installing Python-3.7.7... python-build: use readline from homebrew python-build: use zlib from xcode sdk BUILD FAILED (OS X 15.5 using python-build 2.6.4) Inspect or clean up the working tree at /var/folders/wx/jsppxtm950q5ywpypkvrsq7c0000gn/T/python-build.20250710104639.93089 Results logged to /var/folders/wx/jsppxtm950q5ywpypkvrsq7c0000gn/T/python-build.20250710104639.93089.log Last 10 log lines: checking size of _Bool... 1 checking size of off_t... 8 checking whether to enable large file support... no checking size of time_t... 8 checking for pthread_t... yes checking size of pthread_t... 8 checking size of pthread_key_t... 8 checking whether pthread_key_t is compatible with int... no configure: error: Unexpected output of 'arch' on OSX make: *** No targets specified and no makefile found. Stop.
我已经把pyenv升级到最新版本了,也试过参考《Problems installing python 3.6 with pyenv on Mac OS Big Sur》里的步骤,但还是没解决问题,求帮忙!
解决方案
这个问题我之前帮朋友处理过,主要是因为新的Mac OS版本里arch命令的输出和Python 3.7.7的编译脚本预期不匹配导致的,给你几个亲测有效的解决方法:
方法一:临时切换架构环境安装
这是最直接解决arch报错的方法,先根据你的芯片类型操作:
- 如果是Intel芯片的Mac,直接执行这条命令安装:
ARCHFLAGS="-arch x86_64" pyenv install 3.7.7 - 如果是Apple Silicon芯片的Mac,先安装Rosetta兼容层(如果没装过的话):
然后切换到x86_64的shell环境再安装:softwareupdate --install-rosetta
安装完输入arch -x86_64 zsh ARCHFLAGS="-arch x86_64" pyenv install 3.7.7exit就能回到原来的shell环境。
方法二:补全编译依赖后重试
有时候Xcode组件不全或者依赖库版本不对也会搞砸编译,先更新Command Line Tools:
xcode-select --install
然后更新Homebrew的依赖包,重新装一遍编译需要的库:
brew update brew reinstall openssl readline zlib
最后带着依赖路径参数去安装Python:
CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix readline)/include -I$(brew --prefix zlib)/include" \ LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib" \ pyenv install 3.7.7
方法三:给Python源码打补丁
老版本的Python源码在新Mac OS上编译需要小补丁来适配架构检测逻辑,你可以手动下载补丁再安装:
# 下载适配OSX架构的补丁 curl -L https://github.com/python/cpython/commit/8ea6353.patch?full_index=1 > /tmp/arch.patch # 安装时应用补丁 pyenv install 3.7.7 --patch < /tmp/arch.patch
建议先从方法一开始试,这个解决arch报错的概率最高,要是还不行再试后面的方法。
内容来源于stack exchange




