Can't import objc package with python without sudo permissions.

Tried reinstalling python and mac-os but it didn't solve the problem. Whenever I try to import objc module it raises an error. Also tried activating the virtual environment and trying it there, but I came across the same issue. The error disappears when I try the same but with root access.

>python3 -c 'import objc'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/__init__.py", line 6, in <module>
    from . import _objc
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so, 2): Symbol not found: _FSPathMakeRef
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so

More info is here: https://stackoverflow.com/questions/72367702/import-error-symbol-not-found-fspathmakeref

Posted on Aug 19, 2022 8:03 AM

Reply

Similar questions

4 replies

Aug 19, 2022 12:13 PM in response to La_De_Daweed

No Python 3 distribution, whether from Apple in its developer tools, or from any downloaded distribution, knows about Apple's Python scripting bridge, and without access to that functionality, you cannot import objc, or any other Apple framework.


If you have a /usr/local/bin/pip3, then you can install the PyPy pyobjc package into that user-installed Python3 distribution, and then you can use import objc, from Foundation import NSURL, etc. from the scripting bridge. The installation syntax from the Terminal is:


pip3 install -U pyobjc
pip3 list



Sample using objc after its import.


The first line in your Python scripts should be the following and will work off of your PATH setting:


#!/usr/bin/env python3


Aug 19, 2022 9:26 AM in response to La_De_Daweed

La_De_Daweed wrote:

Can you please tell me how to fix it?

No clue. I might do that kind of thing for my own software I'm developing, but it would be impossible to tell you how to fix it on your own computer. This is one of the "features" of open source software. You haven't paid any money for it, but you have access to all the source. You are now free to learn all about dynamic library loading, fix these bugs, and contribute your patches upstream to whatever project was broken.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can't import objc package with python without sudo permissions.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.