首页 > 解决方案 > 配置:错误:尝试使用 pyenv 安装 python 时,C 编译器无法创建可执行文件

问题描述

尝试通过以下方式安装 python 3:

LDFLAGS="-L/opt/local/lib/" CPPFLAGS="-I/opt/local/include -L/opt /local/lib" C_INCLUDE_PATH="/opt/local/include" LIBRARY_PATH=" /opt/local/lib" pyenv install 3.7.3

我得到:

python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.3.tar.xz...
-> https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
Installing Python-3.7.3...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.15.4 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/qg/bfsy6h2j1_76gh41ngnnwgdh0000gn/T/python-build.20200508155826.1859
Results logged to /var/folders/qg/bfsy6h2j1_76gh41ngnnwgdh0000gn/T/python-build.20200508155826.1859.log

Last 10 log lines:
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... clang
checking whether the C compiler works... no
configure: error: in `/var/folders/qg/bfsy6h2j1_76gh41ngnnwgdh0000gn/T/python-build.20200508155826.1859/Python-3.7.3':
configure: error: C compiler cannot create executables
See `config.log' for more details
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

这个问题的其他解决方案不太一样我没有看到这个与pyenv相关的错误,有什么线索吗?我以前用自制软件安装了 python3,但我怀疑这是考虑到日志中错误的罪魁祸首。

我安装了命令行工具。

标签: pythonpyenv

解决方案


如果您使用 WSL2 ubuntu 并通过 homebrew 安装 pyenv,解决此问题的一种方法是安装build-essential及其朋友。

sudo apt-get update; sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

参考。pyenv 官方指南。它也有 linuxbrew、macOS 和其他操作系统。


推荐阅读