NameError:无法找到 ObjC 类“b”NSEvent”。-PyAutoGui

Bud*_*Bob 5 python importerror pyautogui

pyautogui最近安装了,使用pip3 install pyautogui. 这有效,我在安装时没有收到错误。但是导入模块时如下图所示。

import pyautogui
Run Code Online (Sandbox Code Playgroud)

我很高兴地收到了这个错误消息。

Traceback (most recent call last):
  File "a.py", line 2, in <module>
    import pyautogui
  File "/Users/name/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pyautogui/__init__.py", line 241, in <module>
    import mouseinfo
  File "/Users/name/.pyenv/versions/3.8.2/lib/python3.8/site-packages/mouseinfo/__init__.py", line 107, in <module>
    NSEvent = ObjCClass('NSEvent')
  File "/Users/name/.pyenv/versions/3.8.2/lib/python3.8/site-packages/rubicon/objc/api.py", line 924, in __new__
    ptr, name = cls._new_from_name(name_or_ptr)
  File "/Users/name/.pyenv/versions/3.8.2/lib/python3.8/site-packages/rubicon/objc/api.py", line 827, in _new_from_name
    raise NameError("ObjC Class '%s' couldn't be found." % name)
NameError: ObjC Class 'b'NSEvent'' couldn't be found.
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?是我没有安装正确吗?似乎文档像我一样导入模块。

Bud*_*Bob 7

嗯。我尝试了以下操作。

import AppKit
import pyautogui
Run Code Online (Sandbox Code Playgroud)

没有出现错误消息。我测试了这个答案。

import AppKit
import pyautogui
screenWidth, screenHeight = pyautogui.size()
print((screenWidth, screenHeight))
Run Code Online (Sandbox Code Playgroud)

我没有收到错误并收到了正确的输出。

(1440, 900)
Run Code Online (Sandbox Code Playgroud)