pythonpython-3.xpyautoguidyldpyobjc

Error when importing pyautogui on macOS 10.13 and Python 3.8


I'm working in a conda environment with Python 3.8.0 created using conda create --name atbs python=3.8.0. I have installed pyobjc, pyobc-core and pyautogui using pip install pyautogui. The installation looks successful, and I can run import objc with no errors, but when I run import pyautogui I get the following error message. Can anyone help me figure out what is going on?

Traceback (most recent call last):
  File "/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/pyautogui/_pyautogui_osx.py", line 5, in <module>
    import Quartz
  File "/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/Quartz/__init__.py", line 6, in <module>
    import AppKit
  File "/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/AppKit/__init__.py", line 10, in <module>
    import Foundation
  File "/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/Foundation/__init__.py", line 9, in <module>
    import CoreFoundation
  File "/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/CoreFoundation/__init__.py", line 16, in <module>
    objc.pathForFramework("/System/Library/Frameworks/CoreFoundation.framework"),
  File "/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/objc/_dyld.py", line 148, in pathForFramework
    fpath, name, version = infoForFramework(dyld_find(path))
  File "/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/objc/_dyld.py", line 142, in dyld_find
    return dyld_framework(filename, framework_name, version)
  File "/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/objc/_dyld.py", line 101, in dyld_framework
    if _dyld_shared_cache_contains_path(f):
NotImplementedError: _dyld_shared_cache_contains_path not available

Solution

  • I got the similar issue and found the workaround from https://github.com/hbldh/bleak/issues/372. It works for me too.

    In your file "/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/objc/_dyld.py", replace the following lines

    try:
        from objc._objc import _dyld_shared_cache_contains_path
    except ImportError:
        _dyld_shared_cache_contains_path = None
    

    with

    _dyld_shared_cache_contains_path = None