简体   繁体   English

pyenv 配置:错误:C 编译器无法创建可执行文件

[英]pyenv configure: error: C compiler cannot create executables

I am trying to install multiple versions of Python on my laptop running MacOS Big Sur v11.1.我正在尝试在运行 MacOS Big Sur v11.1 的笔记本电脑上安装多个版本的 Python。 I initially installed xcode command line tools, homebrew, and python via instructions here我最初通过此处的说明安装了 xcode 命令行工具、自制软件和 python

xcode-select --install

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

brew install python

But later on involuntarily upgraded python to 3.9, and I need to go back to 3.7.9.但后来不由自主地将 python 升级到 3.9,我需要将 go 升级回 3.7.9。 So I installed pyenv and attempted to install python 3.7.9 per instructions here所以我安装了 pyenv 并尝试按照此处的说明安装 python 3.7.9

brew install pyenv

pyenv install 3.7.9

But I encountered the following error:但是我遇到了以下错误:

/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.

From other answers online it seems my gcc may be out of date.从网上的其他答案看来,我的 gcc 可能已经过时了。 I checked my gcc version with我检查了我的 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

Which seems to indicate I am on version 4.2.1.这似乎表明我使用的是 4.2.1 版。 I have not been able to find a way to update it on my own yet, but did brew install gcc which did not resolve the problem.我还没有找到自己更新它的方法,但是brew install gcc没有解决问题。 Any help would be much appreciated任何帮助将非常感激

EDIT: Seems pyenv is using clang and not gcc.编辑:似乎 pyenv 使用的是 clang 而不是 gcc。 Perhaps xcode-select installed both?也许 xcode-select 两者都安装了? clang --version returns: 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

This worked for me: I removed the command line tools as root and reinstalled...这对我有用:我以 root 身份删除了命令行工具并重新安装...

Your Command Line Tools (CLT) does not support macOS 11. It is either outdated or was modified.您的命令行工具 (CLT) 不支持 macOS 11。它已过时或已修改。 Please update your Command Line Tools (CLT) or delete it if no updates are available.如果没有可用的更新,请更新您的命令行工具 (CLT) 或将其删除。

Update them from Software Update in System Preferences or run:从系统偏好设置中的软件更新更新它们或运行:

softwareupdate --all --install --force

If that doesn't show you any updates, run:如果这没有显示任何更新,请运行:

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

Alternatively, manually download them from:或者,从以下位置手动下载它们:

https://developer.apple.com/download/more/ . https://developer.apple.com/download/more/

I used the following and it worked我使用了以下,它的工作

CC=gcc pyenv install 3.7.10 CC=gcc pyenv 安装 3.7.10

Seems there is a problem with Xcode, zlib and compiler options.似乎 Xcode、zlib 和编译器选项存在问题。 From brew they made some patches to 3.8.0 python version.从 brew 他们为 3.8.0 python 版本做了一些补丁。

My configuration我的配置

$ 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

This worked for me to install 3.8.3 and 3.9.0这对我安装 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

My sources where I did come up with the solution:我提出解决方案的来源:

For me it was a problem with the clang compiler that pyenv was trying to use.对我来说,pyenv 试图使用的 clang 编译器存在问题。 As I had an active Anaconda version that was set up with pyenv, it tried to use the clang version bundled with Anaconda:由于我有一个使用 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

With:和:

pyenv shell system

I was able to use the XCode clang compiler and everything worked all right.我能够使用 XCode clang 编译器,一切正常。 I was able to install the new version of Python with a typical:我能够安装新版本的 Python 典型:

pyenv install 3.9.5

I know this is a little old but I just ran into the issue and removing and reinstalling command line tools worked for me.我知道这有点老了,但我刚刚遇到了这个问题,删除和重新安装命令行工具对我有用。

Reinstall Xcode, also worked for me!重新安装 Xcode,也为我工作!

nullck➜~» sw_vers                                                                                                                                                                                                                  [11:03:20]
ProductName:    macOS
ProductVersion: 11.5.2
BuildVersion:   20G95
nullck➜~» sudo rm -rf /Library/Developer/CommandLineTools                                                                                                                                                                          [11:03:53]
Password:
sudo: a password is required
nullck➜~» sudo rm -rf /Library/Developer/CommandLineTools                                                                                                                                                                          [11:04:37]
Password:
nullck➜~» xcode-select --install                                                                                                                                                                                                   [11:05:07]
xcode-select: note: install requested for command line developer tools
nullck➜~»                                                                                                                                                                                                                          [11:06:31]
nullck➜~»                                                                                                                                                                                                                          [11:37:33]
nullck➜~» pyenv install 3.10.1                                                                                                                                                                                                     [11:37:34]
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.10.1.tar.xz...
-> https://www.python.org/ftp/python/3.10.1/Python-3.10.1.tar.xz
Installing Python-3.10.1...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.10.1 to /Users/nullck/.pyenv/versions/3.10.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 配置:错误:C 编译器在尝试使用 pyenv 安装 python 时无法创建可执行文件 - configure: error: C compiler cannot create executables when trying to install python with pyenv 由于`configure: error: C compiler cannot create executables`,Pyenv 无法安装 Python 3 的旧版本 - Pyenv unable to install older versions of Python 3 due to `configure: error: C compiler cannot create executables` 配置:错误:C 编译器无法在 buildozer kivy 中创建可执行文件 - configure: error: C compiler cannot create executables in buildozer kivy 配置失败是怎么回事:C编译器无法创建可执行文件(配置:退出77) - What's wrong with configure fail: C compiler cannot create executables(configure: exit 77) 无法配置Python 3.5以在Windows上使用Visual C ++编译器 - Cannot configure Python 3.5 to use Visual C++ compiler on Windows Nest 模拟器:C 编译器无法创建可执行文件 - Nest simulator: C compiler cannot create executable pyenv 出错 - Error with pyenv 无法使用 pyenv 切换 Python - Cannot switch Python with pyenv pycrypto安装:配置错误:无法运行C编译的程序 - pycrypto installation: configure error: cannot run C compiled programs 在pyenv中安装Fabric错误 - Install Fabric error in pyenv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM