I'm trying to automate whatsapp using python in my android phone. I'm using pydroid 3 ide to do it. From the terminal I installed pywhatkit
$ pip install pywhatkit
And i logged into whatsapp web from chrome browser.
Now I've write the script named test.py like this -
import pywhatkit
pywhatkit.sendwhatmsg("+9176xxxxxx18","hello","10,36")
(My number imstead of +9176xxxxxxxx18)
(I've set the time 2 minutes later from my time) But whenever I run the script it throws an error in importing pywhatkit
Something like this -
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "<string>", line 1, in <module>
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pywhatkit/__init__.py", line 8, in <module>
from pywhatkit.main import print_sleep_time, check_window, sendwhatmsg, sendwhatmsg_to_group, info, playonyt, search, close_tab, sendwhatmsg_instantly, sendwhats_image
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pywhatkit/main.py", line 9, in <module>
import pyautogui as pg
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pyautogui/__init__.py", line 249, in <module>
import mouseinfo
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/os.py", line 675, in __getitem__
raise KeyError(key) from None
KeyError: 'DISPLAY'
[Program finished]
Image :- enter image description here
I can't understand why I'm getting this error please help me.let me know if there any other way to send whatsapp messege using python on android? I also have a terminal termux on my android which runs on linux into bash [my desi terminal 😂]
I see you are trying to run from mobile[android] device, this module requires PC browser. So it wont be able to run in your mobile. Try running test.py through your PC. And you cant send whatsapp messege using python on android.