I was making a program which needed pywhatkit module to send messages.I was running this on PythonAnywhere but I don't think that is the one that is causing the problem.
Here is the code:
import pywhatkit
pywhatkit.sendwhatmsg("+91**********","hi",16,50)
But after importing pywhatkit ,I got this error:
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
>>>
So is there any way to solve this?
PyWhatKit requires Chrome or any other browser with UI, i.e. you can't use it on servers as they use browsers in headless mode. Please consider using selenium.