为什么pyauto gui和pycharm对我不起作用?

2022-02-23 00:00:00 python pycharm pyautogui

问题描述

import pyautogui
pyautogui.PAUSE = 1
pyautogui.FAILSAFE = True

pyautogui.click(274, 783)

我在Mac上运行PyCharm。我已经尝试通过PIP3从解释器和终端安装pyautogui。我正在尝试运行一个简单的测试,看看它是否能为我单击一次鼠标,但响应为:

/Users/user/PycharmProjects/NewContractBuyingMacro/venv/bin/python "/Users/user/PycharmProjects/NewContractBuyingMacro/Buying FD Macro 1.py"
Traceback (most recent call last):
  File "/Users/user/PycharmProjects/NewContractBuyingMacro/Buying FD Macro 1.py", line 3, in <module>
    import pyautogui
  File "/Users/user/PycharmProjects/NewContractBuyingMacro/venv/lib/python2.7/site-packages/pyautogui/__init__.py", line 241, in <module>
    import mouseinfo
  File "/Users/user/PycharmProjects/NewContractBuyingMacro/venv/lib/python2.7/site-packages/mouseinfo/__init__.py", line 100, in <module>
    from rubicon.objc import ObjCClass, CGPoint
  File "/Users/user/PycharmProjects/NewContractBuyingMacro/venv/lib/python2.7/site-packages/rubicon/objc/__init__.py", line 3, in <module>
    from .runtime import (  # noqa: F401
  File "/Users/user/PycharmProjects/NewContractBuyingMacro/venv/lib/python2.7/site-packages/rubicon/objc/runtime.py", line 785
    self.restype, *self.argtypes = ctypes_for_method_encoding(self.encoding)
                  ^
SyntaxError: invalid syntax

我以为这可能与Mac不想让程序控制鼠标有关,但现在我不这么认为。我想应该是简单的东西。感谢您的任何帮助。

PyCharm

可能发生此问题的一个原因是,推荐答案上的Python解释器是较旧的版本(2.7或更早)。将解释器更改为Python 3将解决此问题。

Pyautogui仅与最新版本的Python一起运行,并且不支持任何旧版本的Python。要更改解释器,请导航到设置>;首选项>;python解释器,然后选择python3解释器(解释器的位置-/usr/bin/python3)。 如果您无法更换解释器,请参阅视频教程

相关文章