I changed the following setting on the raspberry and all issues with pyautogui are gone. sudo raspi-config 6 Advanced - Options Configure advanced settings A6 Wayland -Switch between X and Wayland backends W1 X11 - Openbox window manager with X11 backend