pythonpython-3.xmacospippyobjc

Error installing Pyobjc on macOS 11.0 Big Sur


I'm getting an error when trying to install the 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.

Here's the beginning of the error:

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/

And here's the end of the error:

    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.

I've tried reinstalling Xcode developer tools to no avail, as I thought this might refresh the SDK references. Any help would be much appreciated.


Solution

  • I believe the issue should be resolved by now. So running pip install pyobjc should be working again as expected (tested for pyobjc-7.0.1 and python3.9.0).

    If not, you can set the SDK temporarily for the current session and build it from scratch with:

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

    (If it doesn't work, check what SDKs you have installed. It worked for me with MacOSX10.15, just run ls /Library/Developer/CommandLineTools/SDKs/ and see what's available. You need the Xcode CLI tools for this.) After that just run pip install pyobjc again to install the rest of pyobjc.

    For some framework addons you might have to set cflags specifically with:

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

    Again just switch MacOSX10.14.sdk with a 10.X SDK on your system.

    There's more information on this related GitHub issue from which i shamelessly stole this solution from @hoefling on s.o. <3