asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.24k forks source link

Pyautogui does not function on the latest raspberry piOS (Debian Bookworm) #820

Closed JackLawrenceCRISPR closed 11 months ago

JackLawrenceCRISPR commented 11 months ago

Pyautogui does not function on the latest raspberry piOS based on Debian Bookworm. I've only tested the piOS, but other Debian Bookworm releases may share the same issue. Pyautogui did work on Debian Bullseye.

Steps to replicate:

  1. Flash a fresh standard full x64 Bookworm based piOS released 10-10-2023 and setup.
  2. Create a python venv and activate it
  3. pip install pyautogui
  4. python
  5. import pyautogui
  6. pyautogui.position() -> (0,0)

You can also do the following :

  1. After a fresh install, run "sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED" to disable pip protection (please don't do this if you intend to keep using your piOS installation afterwards)
  2. sudo pip install pyautogui
  3. sudo python
  4. import pyautogui
  5. pyautogui.position() -> (0,0)

Problems also persist with pip3.

Mouse movement, clicks and identify position do not function: nothing happens but no errors are raised.

Position will always be 0,0 (or 500,500 depending on your setup). This issue also affects another mouse module https://pypi.org/project/mouse/ with identical results for their "mouse.get_position".

JackLawrenceCRISPR commented 11 months ago

The root cause of the incompatibility: https://www.raspberrypi.com/news/bookworm-the-new-version-of-raspberry-pi-os/

"the move to using Wayland rather than X11 as the display system."

PyAutoGui (and Mouse) use X11 api for their linux support.

As such, the issue is addressed in the following thread: https://github.com/asweigart/pyautogui/issues/111

I redirect any further discussion regarding piOS or Debian 12.0>= compatibility to the aforementioned Wayland support thread.

The Wayland support thread offer some potential alternatives to pyautogui and mouse functions. Some users in the thread have suggested the following modules: evemu, python-evdev, keyboard, ydotool. Please read the aforementioned thread for further discussion about the features and limitations of each module.

JackLawrenceCRISPR commented 11 months ago

See previous comment.