python-3.x 如何导入pyautogui而不抛出错误

uklbhaso  于 2023-06-07  发布在  Python
关注(0)|答案(1)|浏览(191)

import pyautogui抛出错误

Python 3.10.8 (main, Apr  9 2023, 15:38:43) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyautogui
Traceback (most recent call last):
  File "/home/juan/.local/lib/python3.10/site-packages/Xlib/xauth.py", line 43, in __init__
    raw = open(filename, 'rb').read()
FileNotFoundError: [Errno 2] No such file or directory: '/home/juan/.Xauthority'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/juan/.local/lib/python3.10/site-packages/pyautogui/__init__.py", line 246, in <module>
    import mouseinfo
  File "/home/juan/.local/lib/python3.10/site-packages/mouseinfo/__init__.py", line 223, in <module>
    _display = Display(os.environ['DISPLAY'])
  File "/home/juan/.local/lib/python3.10/site-packages/Xlib/display.py", line 80, in __init__
    self.display = _BaseDisplay(display)
  File "/home/juan/.local/lib/python3.10/site-packages/Xlib/display.py", line 62, in __init__
    display.Display.__init__(*(self, ) + args, **keys)
  File "/home/juan/.local/lib/python3.10/site-packages/Xlib/protocol/display.py", line 60, in __init__
    auth_name, auth_data = connect.get_auth(self.socket,
  File "/home/juan/.local/lib/python3.10/site-packages/Xlib/support/connect.py", line 91, in get_auth
    return mod.get_auth(sock, dname, host, dno)
  File "/home/juan/.local/lib/python3.10/site-packages/Xlib/support/unix_connect.py", line 103, in new_get_auth
    au = xauth.Xauthority()
  File "/home/juan/.local/lib/python3.10/site-packages/Xlib/xauth.py", line 45, in __init__
    raise error.XauthError('~/.Xauthority: %s' % err)
Xlib.error.XauthError: ~/.Xauthority: [Errno 2] No such file or directory: '/home/juan/.Xauthority'
1bqhqjot

1bqhqjot1#

你可以尝试卸载pyautogui:pip uninstall pyautogui,然后使用以下命令安装它:python3 -m pip install pyautogui,此命令在pyautogui的文档中。希望能帮到你。

相关问题