getting "Xlib.error.DisplayConnectionError:"on importing Pywhatkit in PythonAnywhere

getting "Xlib.error.DisplayConnectionError:"on importing Pywhatkit in PythonAnywhere

我正在制作一个需要 pywhatkit 模块发送的程序 messages.I 在 PythonAnywhere 上是 运行 这个,但我认为这不是导致问题的原因。

代码如下:

import pywhatkit
pywhatkit.sendwhatmsg("+91**********","hi",16,50)

但是在导入 pywhatkit 之后,我得到了这个错误:

Traceback (most recent call last):
  File "/home/code2d/.local/lib/python3.8/site-packages/Xlib/support/unix_connect.py", line 76, in get_socket
    s.connect('/tmp/.X11-unix/X%d' % dno)
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/code2d/pyw.py", line 7, in <module>
    import pyautogui as pg
  File "/home/code2d/.local/lib/python3.8/site-packages/pyautogui/__init__.py", line 241, in <module>
    import mouseinfo
  File "/home/code2d/.local/lib/python3.8/site-packages/mouseinfo/__init__.py", line 223, in <module>
    _display = Display(os.environ['DISPLAY'])
  File "/home/code2d/.local/lib/python3.8/site-packages/Xlib/display.py", line 80, in __init__
    self.display = _BaseDisplay(display)
  File "/home/code2d/.local/lib/python3.8/site-packages/Xlib/display.py", line 62, in __init__
    display.Display.__init__(*(self, ) + args, **keys)
  File "/home/code2d/.local/lib/python3.8/site-packages/Xlib/protocol/display.py", line 58, in __init__
    self.socket = connect.get_socket(name, host, displayno)
Traceback (most recent call last):
  File "/home/code2d/.local/lib/python3.8/site-packages/Xlib/support/unix_connect.py", line 76, in get_socket
    s.connect('/tmp/.X11-unix/X%d' % dno)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/code2d/pyw.py", line 1, in <module>
    import pywhatkit
  File "/home/code2d/.local/lib/python3.8/site-packages/pywhatkit/__init__.py", line 7, in <module>
    from pywhatkit.main import print_sleep_time, check_window, sendwhatmsg, sendwhatmsg_to_group, sendwhatmsg_instantly, info, playonyt, search
  File "/home/code2d/.local/lib/python3.8/site-packages/pywhatkit/main.py", line 3, in <module>
    import pyautogui as pg
  File "/home/code2d/.local/lib/python3.8/site-packages/pyautogui/__init__.py", line 241, in <module>
    import mouseinfo
  File "/home/code2d/.local/lib/python3.8/site-packages/mouseinfo/__init__.py", line 223, in <module>
    _display = Display(os.environ['DISPLAY'])
  File "/home/code2d/.local/lib/python3.8/site-packages/Xlib/display.py", line 80, in __init__
    self.display = _BaseDisplay(display)
  File "/home/code2d/.local/lib/python3.8/site-packages/Xlib/display.py", line 62, in __init__
    display.Display.__init__(*(self, ) + args, **keys)
  File "/home/code2d/.local/lib/python3.8/site-packages/Xlib/protocol/display.py", line 58, in __init__
    self.socket = connect.get_socket(name, host, displayno)
  File "/home/code2d/.local/lib/python3.8/site-packages/Xlib/support/connect.py", line 76, in get_socket
    return mod.get_socket(dname, host, dno)
  File "/home/code2d/.local/lib/python3.8/site-packages/Xlib/support/unix_connect.py", line 78, in get_socket
    raise error.DisplayConnectionError(dname, str(val))
Xlib.error.DisplayConnectionError: Can't connect to display ":0": [Errno 2] No such file or directory
>>> 

那么有什么办法可以解决吗?

PyWhatKit 需要 Chrome 或任何其他具有 UI 的浏览器,即您不能在服务器上使用它,因为它们在无头模式下使用浏览器。请考虑使用硒。