在 macOS 11.0 Big Sur 上安装 Pyobjc 时出错

Error installing Pyobjc on macOS 11.0 Big Sur

我在尝试安装 pyobjc library in a virtual environment on Big Sur. The installation errors out claiming that it "Cannot determine SDK version." I've done some digging, and it looks like this error is triggered by an exception in this flow 时遇到错误。

这是错误的开头:

Building wheel for pyobjc-core (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/me/Desktop/Projects/env/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-qixc6c89/pyobjc-core/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-qixc6c89/pyobjc-core/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/tmp/pip-wheel-c0phpdjv
       cwd: /private/tmp/pip-install-qixc6c89/pyobjc-core/

这是错误的结尾:

    copying PyObjCTest/test_specialtypecodes_methdef.py -> build/lib.macosx-11.0-x86_64-3.9/PyObjCTest
    running build_ext
    Cannot determine SDK version
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/me/Desktop/Projects/env/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-qixc6c89/pyobjc-core/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-qixc6c89/pyobjc-core/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/tmp/pip-record-l_v97344/install-record.txt --single-version-externally-managed --compile --install-headers /Users/me/Desktop/Projects/env/include/site/python3.9/pyobjc-core Check the logs for full command output.

我已经尝试重新安装 Xcode 开发人员工具但没有成功,因为我认为这可能会刷新 SDK 参考。任何帮助将不胜感激。

我也 运行 解决了这个问题,设法通过从 /Library/Developer/CommandLineTools/SDKs 中删除符号链接和除 11.0 以外的所有 SDK 来解决它。不完全确定这对系统稳定性或其他软件有何影响,但 pip install pyobjc 确实完成了。

我不自称是 MacOS 开发专家,所以 YMMV。

我相信这个问题现在应该已经解决了。所以 运行ning pip install pyobjc 应该按预期再次工作(测试 pyobjc-7.0.1 和 python3.9.0 ).

如果没有,您可以为当前会话临时设置 SDK,然后从头开始构建它:

SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk pip wheel pyobjc-core

(如果它不起作用,请检查您安装了哪些 SDK。它对我来说适用于 MacOSX10.15,仅 运行 ls /Library/Developer/CommandLineTools/SDKs/ 并查看可用的内容。您需要Xcode CLI 工具。) 之后只需 运行 pip install pyobjc 再次安装 pyobjc 的其余部分。

对于某些框架插件,您可能必须专门设置 cflags:

SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk \
    CFLAGS="-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk" \
    pip wheel pyobjc-framework-cocoa

同样只需在您的系统上使用 10.X SDK 切换 MacOSX10.14.sdk

s.o 上有关于 this related GitHub issue from which i shamelessly stole this solution from @hoefling 的更多信息。 <3

PyObjC 应该使用二进制轮安装(无需编译)。如果没有,请在 GitHub 中提出问题,并提供有关 Python 安装的信息(例如 Python 的安装方式)。