在 macOS 10.13 和 Python 3.8 上导入 pyautogui 时出错
Error when importing pyautogui on macOS 10.13 and Python 3.8
我在 conda
环境中工作,其中 Python 3.8.0 使用 conda create --name atbs python=3.8.0
创建。我已经使用 pip install pyautogui
安装了 pyobjc
、pyobc-core
和 pyautogui
。安装看起来成功,我可以 运行 import objc
没有错误,但是当我 运行 import pyautogui
时,我收到以下错误消息。谁能帮我弄清楚这是怎么回事?
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
我遇到了类似的问题并找到了解决方法
https://github.com/hbldh/bleak/issues/372。它也适用于我。
在您的文件“/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/objc/_dyld.py”中,替换以下行
try:
from objc._objc import _dyld_shared_cache_contains_path
except ImportError:
_dyld_shared_cache_contains_path = None
与
_dyld_shared_cache_contains_path = None
我在 conda
环境中工作,其中 Python 3.8.0 使用 conda create --name atbs python=3.8.0
创建。我已经使用 pip install pyautogui
安装了 pyobjc
、pyobc-core
和 pyautogui
。安装看起来成功,我可以 运行 import objc
没有错误,但是当我 运行 import pyautogui
时,我收到以下错误消息。谁能帮我弄清楚这是怎么回事?
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
我遇到了类似的问题并找到了解决方法 https://github.com/hbldh/bleak/issues/372。它也适用于我。
在您的文件“/opt/anaconda3/envs/atbs/lib/python3.8/site-packages/objc/_dyld.py”中,替换以下行
try:
from objc._objc import _dyld_shared_cache_contains_path
except ImportError:
_dyld_shared_cache_contains_path = None
与
_dyld_shared_cache_contains_path = None