如何解决pyenv 配置:错误:C 编译器无法创建可执行文件
我正在尝试在运行 MacOS Big Sur v11.1 的笔记本电脑上安装多个版本的 Python。我最初通过指令安装了 xcode 命令行工具、自制软件和 python here
xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install python
但后来不由自主地将python升级到3.9,我需要回到3.7.9。所以我安装了 pyenv 并尝试按照说明安装 python 3.7.9 here
brew install pyenv
pyenv install 3.7.9
但是我遇到了以下错误:
/var/folders/8n/ml0qwc091w9bhpszzxy9djl00000gn/T/python-build.20210118111111.56108 /usr/local/Cellar
/var/folders/8n/ml0qwc091w9bhpszzxy9djl00000gn/T/python-build.20210118111111.56108/Python-3.7.9 /var/folders/8n/ml0qwc091w9bhpszzxy9djl00000gn/T/python-build.20210118111111.56108 /usr/local/Cellar
checking build system type... x86_64-apple-darwin20.2.0
checking host system type... x86_64-apple-darwin20.2.0
checking for python3.7... no
checking for python3... python3
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/8n/ml0qwc091w9bhpszzxy9djl00000gn/T/python-build.20210118111111.56108/Python-3.7.9':
configure: error: C compiler cannot create executables
See `config.log' for more details
make: *** No targets specified and no makefile found. Stop.
从网上的其他答案看来,我的 gcc 可能已经过时了。我用
检查了我的gcc版本[/usr/local/Cellar]$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr
--with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 11.0.3 (clang-1103.0.32.62) Target: x86_64-apple-darwin20.2.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
这似乎表明我使用的是 4.2.1 版。我还没有找到自己更新它的方法,但是做了 brew install gcc
并没有解决问题。任何帮助将不胜感激
编辑:
似乎 pyenv 正在使用 clang 而不是 gcc。也许 xcode-select 都安装了? clang --version
返回:
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
解决方法
这对我有用:我以 root 身份删除了命令行工具并重新安装...
您的命令行工具 (CLT) 不支持 macOS 11。 它要么已经过时,要么已被修改。 请更新您的命令行工具 (CLT),如果没有可用更新,请将其删除。
从系统偏好设置中的软件更新更新它们或运行:
softwareupdate --all --install --force
如果没有显示任何更新,请运行:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
或者,从以下位置手动下载它们:
https://developer.apple.com/download/more/。
,Xcode、zlib 和编译器选项似乎有问题。从 brew 开始,他们做了一些补丁到 3.8.0 python 版本。
我的配置
$ sw_vers
ProductName: macOS
ProductVersion: 11.2.3
BuildVersion: 20D91
$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
这对我来说安装 3.8.3 和 3.9.0
# Resinstall Xcode
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
# Install zlib and bzip2 using brew
brew reinstall zlib bzip2
# Install tcl-tk tkinter
brew install tcl-tk
# Uninstall previous versions from python
pyenv uninstall 3.8.3
pyenv uninstall 3.9.0
# Install python 3.8.3 patched
env \
PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
LDFLAGS="-L$(brew --prefix tcl-tk)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
CPPFLAGS="-I$(brew --prefix tcl-tk)/include -L$(brew --prefix zlib)/include -L$(brew --prefix bzip2)/include" \
PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
CFLAGS="-I$(brew --prefix tcl-tk)/include -I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix zlib)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-I$(brew --prefix tcl-tk)/lib -L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib"
pyenv install --patch 3.8.3 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
env \
PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
LDFLAGS="-L$(brew --prefix tcl-tk)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
CPPFLAGS="-I$(brew --prefix tcl-tk)/include -L$(brew --prefix zlib)/include -L$(brew --prefix bzip2)/include" \
PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
CFLAGS="-I$(brew --prefix tcl-tk)/include -I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix zlib)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-I$(brew --prefix tcl-tk)/lib -L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib"
pyenv install 3.9.0
我提出解决方案的来源:
- pyenv configure: error: C compiler cannot create executables
- unable to install python 3.8.0 on macox 11 #1740
- Unable to build Python on macOS Big Sur with Xcode 12 beta #1643
我使用了以下方法并且有效
CC=gcc pyenv 安装 3.7.10
,对我来说,pyenv 试图使用的 clang 编译器有问题。由于我有一个使用 pyenv 设置的活动 Anaconda 版本,它尝试使用与 Anaconda 捆绑在一起的 clang 版本:
$ clang --version
clang version 10.0.0
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Users/myuser/.pyenv/versions/anaconda3-2020.02/bin
与:
pyenv shell system
我能够使用 XCode clang 编译器并且一切正常。我能够使用典型的方式安装新版本的 Python:
pyenv install 3.9.5
,
我知道这有点旧,但我刚刚遇到了这个问题,删除并重新安装命令行工具对我有用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。