python - pyenv 配置:错误:C 编译器无法创建可执行文件
问题描述
我正在尝试在运行 MacOS Big Sur v11.1 的笔记本电脑上安装多个版本的 Python。我最初通过此处的说明安装了 xcode 命令行工具、自制软件和 python
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
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
或者,从以下位置手动下载它们:
推荐阅读
- android - Android BLE 广告 UUID 长度在不同的 SDK 级别上有所不同?
- holoviews - hvplot 热图排序轴
- sql - 如何使用 PL/SQL 中的过程在表中搜索记录?
- c++ - 如何将静音音频数据写入音频流?
- javascript - React-Native 中更快的数组循环
- go - 如何在 Go 中创建多级错误子类型
- javascript - 在 Hexo 中实施分类法(分组类别)的正确方法是什么?
- powershell - 范围标头必须使用适当的属性或方法
- c# - Web应用程序中的会话变量丢失
- python-3.x - 如何在没有重复的情况下找到矩阵中点之间的所有距离?