使用pyenv在Mac上安装Python 3.9.0失败求助
pyenv安装Python 3.9.0构建失败解决(macOS 13.6.7)
我已安装Python 3.12,需要同时使用Python 3.9,但通过pyenv安装3.9.0时构建失败,执行命令及报错信息如下:
sudo pyenv install 3.9.0 python-build: use openssl@1.1 from homebrew python-build: use readline from homebrew Downloading Python-3.9.0.tar.xz... -> https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tar.xz Installing Python-3.9.0... python-build: use readline from homebrew python-build: use zlib from xcode sdk BUILD FAILED (OS X 13.6.7 using python-build 1.2.21) Inspect or clean up the working tree at /tmp/python-build.20240806171953.65977 Results logged to /tmp/python-build.20240806171953.65977.log
日志片段:
(.venv) rmanoj@C02D76RZMD6R cicd % cat /tmp/python-build.20240806171953.65977.log /tmp/python-build.20240806171953.65977 ~/cicd /tmp/python-build.20240806171953.65977/Python-3.9.0 /tmp/python-build.20240806171953.65977 ~/cicd checking build system type... x86_64-apple-darwin22.6.0 checking host system type... x86_64-apple-darwin22.6.0 checking for python3.9... python3.9 checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... "darwin" checking for gcc... clang 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 clang accepts -g... yes checking for clang option to accept ISO C89... none needed checking how to run the C preprocessor... clang -E checking for grep that handles long lines and -e... /usr/bin/grep checking for a sed that does not truncate output... /usr/local/bin/gsed checking for --with-cxx-main=<compiler>... no checking for clang++... no configure:
解决方法
1. 补全C++编译器
日志明确显示找不到clang++,先安装Xcode命令行工具:
xcode-select --install
若已安装,重置路径确保生效:
sudo xcode-select --reset
2. 更新并安装依赖库
通过Homebrew更新依赖,确保pyenv所需库完整:
brew update brew install openssl@1.1 readline zlib
3. 指定依赖路径安装Python 3.9.0
不要用sudo执行pyenv安装(pyenv是用户级工具,sudo会导致权限问题),直接用以下命令传递依赖路径:
env PATH="$(brew --prefix openssl@1.1)/bin:$(brew --prefix readline)/bin:$(brew --prefix zlib)/bin:$PATH" \ LDFLAGS="-L$(brew --prefix openssl@1.1)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib" \ CPPFLAGS="-I$(brew --prefix openssl@1.1)/include -I$(brew --prefix readline)/include -I$(brew --prefix zlib)/include" \ pyenv install 3.9.0
4. 验证安装结果
安装完成后切换版本并检查:
pyenv global 3.9.0 python --version # 正常会显示Python 3.9.0
内容的提问来源于stack exchange,提问作者Manoj Ramakrishnan
相关产品推荐
相关产品推荐

