python - 安装 `dulwich` 给出 `error: command ' clang' failed with exit status 1`

标签 python clang macos-mojave

当我尝试执行pip install dulwich时,我最终看到了一堵红色的墙,提示clang。这是最后一点:

    Please check your Xcode installation
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/openssl/include -I/usr/local/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/sqlite/include -I/Users/alaird/Developer/py3venv/include -I/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c dulwich/_objects.c -o build/temp.macosx-10.14-x86_64-3.7/dulwich/_objects.o
    clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]
    In file included from dulwich/_objects.c:20:
    /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:25:10: fatal error: 'stdio.h' file not found
    #include <stdio.h>
             ^~~~~~~~~
    1 error generated.
    error: command 'clang' failed with exit status 1
    ----------------------------------------
ERROR: Command "/Users/alaird/Developer/py3venv/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/63/r_rf7mhj14b4c42mfkkl06t8rg1b1r/T/pip-install-b9wlh7xh/dulwich/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/63/r_rf7mhj14b4c42mfkkl06t8rg1b1r/T/pip-record-_v0dq_sp/install-record.txt --single-version-externally-managed --compile --install-headers /Users/alaird/Developer/py3venv/include/site/python3.7/dulwich" failed with error code 1 in /private/var/folders/63/r_rf7mhj14b4c42mfkkl06t8rg1b1r/T/pip-install-b9wlh7xh/dulwich/

我在 Google 上遇到过很多“clang failed with exit status 1”兔子洞,问题是这太笼统了。回答几个问题:

  1. 是的,Xcode 是最新版本,并且已安装命令行工具(我使用的是 OS X 10.14.6,因此现在通过应用更新进行管理)。
  2. 这是一个之前可以运行的安装。这个错误是在我执行 make clean 后开始出现的,这让我的 venv 崩溃了。
  3. 尝试安装最新的 setuptools 会遇到相同的错误,因此感觉指向 Xcode/我的构建环境(而不是 dulwich)的错误是正确的罪魁祸首。
  4. 进行 brew 更新 也会给我带来相同的 clang barf。我认为当我升级到 Mojave 时,有些东西被破坏了。

想法?

最佳答案

啊哈!

我开始查看警告而不是错误:

no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]

这让我注意到 SDK 版本号是硬编码的......这看起来很愚蠢。所以我建立了一个符号链接(symbolic link):

ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk

根据您的系统配置,您可能需要构建不同的符号链接(symbolic link)(还有一个 MacOSX10.15.sdk 文件夹)。

然后就成功了! pip 没有问题(包括安装 dulwichpycrypto),brew 没有问题,一切都很好又是我的开发环境了!

我也这么做了:

export CFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"

但是,我不相信这就是它的作用,因为在开始新 session 后,一切仍然有效。所以可能是上面的符号链接(symbolic link)解决了这个问题。希望这对其他人有帮助!

关于python - 安装 `dulwich` 给出 `error: command ' clang' failed with exit status 1`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58458683/

相关文章:

python - 如何在 Qt Designer 中推广的 QVideoWidget 中播放视频?

c++ - OpenCV c++ 找不到 <opencv2/face.hpp>

xcode - "bad codegen, pointer diff in boost"32 位构建错误

objective-c - 使用 Clang 将关键字添加到 Objective-C

python - 在 MacOS Mojave 上通过 Homebrew 安装 Python 2 时出错

debugging - Xcode 11.2.1 上的 com.apple.dt.SKAgent 消耗所有资源

python - Mac安装后找不到ipython

python - 如何使用 lxml 仅检索可见节点文本

python - 使用 Python 创建 openoffice .odt 文档

Valgrind 适用于 macOS Mojave 10.14.2?还有其他选择吗?