macOS Ventura 13.5下无法通过pyenv安装Python版本求助
问题:pyenv安装Python 3.11.4失败,提示C编译器无法生成可执行文件
执行命令
pyenv install 3.11.4
报错信息
python-build: use openssl@1.1 from homebrew python-build: use readline from homebrew Downloading Python-3.11.4.tar.xz... -> https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tar.xz Installing Python-3.11.4... python-build: use tcl-tk from homebrew python-build: use readline from homebrew BUILD FAILED (OS X 13.5 using python-build 20180424) Inspect or clean up the working tree at /var/folders/kv/l0jzxgbj1kggff_kd35bfzkw0000gn/T/python-build.20230728132126.31601 Results logged to /var/folders/kv/l0jzxgbj1kggff_kd35bfzkw0000gn/T/python-build.20230728132126.31601.log Last 10 log lines: checking pkg-config is at least version 0.9.0... yes checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... "darwin" checking for gcc... x86_64-apple-darwin13.4.0-clang checking whether the C compiler works... no configure: error: in `/var/folders/kv/l0jzxgbj1kggff_kd35bfzkw0000gn/T/python-build.20230728132126.31601/Python-3.11.4': configure: error: C compiler cannot create executables See `config.log' for more details make: *** No targets specified and no makefile found. Stop.
环境信息
- macOS Ventura 13.5
- CommandLineTools版本:14.3.1.0.1.1683849156
解决方法
1. 重置CommandLineTools路径
macOS Ventura下可能存在CLT路径错乱问题,执行命令重置:
sudo xcode-select --reset
重启终端后重试安装。
2. 指定编译器参数
通过环境变量跳过编译器警告转错误的限制:
CFLAGS="-Wno-error=implicit-function-declaration" pyenv install 3.11.4
3. 更新pyenv及python-build
当前使用的python-build版本为20180424,版本过旧不兼容新系统,执行更新:
- Homebrew安装的pyenv:
brew upgrade pyenv
- Git克隆安装的pyenv:
cd ~/.pyenv && git pull cd ~/.pyenv/plugins/python-build && git pull
4. 修复Homebrew依赖
重新安装相关依赖并设置环境变量:
brew reinstall openssl@1.1 readline tcl-tk
设置环境变量后重试:
export PATH="/usr/local/opt/openssl@1.1/bin:$PATH" export PATH="/usr/local/opt/readline/bin:$PATH" export PATH="/usr/local/opt/tcl-tk/bin:$PATH" export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/tcl-tk/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/readline/include -I/usr/local/opt/tcl-tk/include" pyenv install 3.11.4
5. 查看详细错误日志
若以上方法无效,查看编译日志定位具体问题:
cat /var/folders/kv/l0jzxgbj1kggff_kd35bfzkw0000gn/T/python-build.20230728132126.31601/config.log
重点关注checking whether the C compiler works... no之前的错误信息,通常会明确缺失的依赖或权限问题。
内容的提问来源于stack exchange,提问作者PeeteKeesel
相关产品推荐
相关产品推荐

