ronaldoussoren/pyobjc

Import Error: cannot import name '_objc

Closed this issue · 3 comments

Describe the bug
A clear and concise description of what the bug is.

Traceback (most recent call last):
  File "/users/kylefoley/documents/pcode/other/activities.py", line 10, in <module>
    from general import *
  File "/users/kylefoley/documents/pcode/general/__init__.py", line 3, in <module>
    import general.very_general_functions as vgf
  File "/users/kylefoley/documents/pcode/general/very_general_functions.py", line 10, in <module>
    import requests, keyboard
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/keyboard/__init__.py", line 126, in <module>
    from. import _darwinkeyboard as _os_keyboard
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/keyboard/_darwinkeyboard.py", line 3, in <module>
    import Quartz
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/Quartz/__init__.py", line 47, in <module>
    globals().pop("_setup")()
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/Quartz/__init__.py", line 7, in _setup
    import AppKit
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/AppKit/__init__.py", line 148, in <module>
    globals().pop("_setup")()
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/AppKit/__init__.py", line 12, in _setup
    import Foundation
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/Foundation/__init__.py", line 188, in <module>
    globals().pop("_setup")()
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/Foundation/__init__.py", line 12, in _setup
    import CoreFoundation
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/CoreFoundation/__init__.py", line 37, in <module>
    globals().pop("_setup")()
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/CoreFoundation/__init__.py", line 12, in _setup
    import objc
  File "/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/objc/__init__.py", line 6, in <module>
    from . import _objc
ImportError: cannot import name '_objc' from partially initialized module 'objc' (most likely due to a circular import) (/Users/kylefoley/Documents/pcode/venv3/lib/python3.11/site-packages/objc/__init__.py)

Platform information

  • Python version - 3.11.7
  • How was python installed (downloaded from website)
  • macOS version - 13.6.3

To Reproduce
python
import pyobjc

I cannot reproduce this locally, even when first installing the keyboard package on PyPI and importing that.

Also, the "to reproduce" bits are not how to reproduce your issue, you're clearly doing something else than "import pyobjc" as the latter will raise ImportError due to not find "pyobjc".

I'm closing this issue because I cannot reproduce locally. I'll reopen if you have a clear reproducer.

I am having the same issue when trying to import NSSound from AppKit:

from AppKit import NSSound

ImportError: cannot import name '_objc' from partially initialized module 'objc' (most likely due to a circular import)

Import succeeds on a fresh virtual environment for a few times.
Then it breaks and the only fix seems to be to reinstall the environment.

Platform:
Python version - 3.11
macOS version - 12.1