无法导入 pynput.mouse 控制器、按钮
Posted
技术标签:
【中文标题】无法导入 pynput.mouse 控制器、按钮【英文标题】:Can't import pynput.mouse Controller, Button 【发布时间】:2021-12-29 14:24:03 【问题描述】:我已经在终端中使用这两个命令安装了 pynput。
pip install pynput
python -m pip install pynput
两者都能正常工作,而且似乎软件包已正确安装 - 在终端中检查。
但是当我跑步时:
from pynput.mouse import Controller, Button
我不断收到此错误:
Traceback (most recent call last):
File "/Users/user/Desktop/MyApp/whatsapp_bot.py", line 3, in <module>
import pynput.mouse
File "/Users/user/PycharmProjects/Le1/venv/lib/python3.8/site-packages/pynput/__init__.py", line 40, in <module>
from . import keyboard
File "/Users/user/PycharmProjects/Le1/venv/lib/python3.8/site-packages/pynput/keyboard/__init__.py", line 31, in <module>
backend = backend(__name__)
File "/Users/user/PycharmProjects/Le1/venv/lib/python3.8/site-packages/pynput/_util/__init__.py", line 70, in backend
return importlib.import_module('._' + module, package)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/user/PycharmProjects/Le1/venv/lib/python3.8/site-packages/pynput/keyboard/_darwin.py", line 51, in <module>
from pynput._util.darwin import (
File "/Users/user/PycharmProjects/Le1/venv/lib/python3.8/site-packages/pynput/_util/darwin.py", line 60, in <module>
OBJC.PyObjCObject_New.restype = ctypes.py_object
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 386, in __getattr__
func = self.__getitem__(name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 391, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x7fe4f8c899c0, PyObjCObject_New): symbol not found
我正在运行最新的 python 版本 3.8 和 pip 20.1.1 可能是什么问题?
【问题讨论】:
您是否尝试重新安装? 是的,没用 【参考方案1】:https://github.com/moses-palmer/pynput/issues/420 最新的 Pyobjc 打破了 pynput。将其降级到 7.3 可解决此问题。
学分:Error while importing pynput - dlsym(0x7f90f7d0c310, PyObjCObject_New): symbol not found
【讨论】:
我已经安装了 pyobjc 并将其降级到 7.3 - 仍然无法正常工作,我得到了同样的错误。以上是关于无法导入 pynput.mouse 控制器、按钮的主要内容,如果未能解决你的问题,请参考以下文章
python实战===python控制键盘鼠标:pynput