Skip to content

ImageGrab.grab() Fails to detect that I'm on Wayland #9139

@Desyncfy

Description

@Desyncfy

What did you do?

I used ImageGrab.grab() on Hyprland.

What did you expect to happen?

Auto-detect that I was using Wayland with grim installed and attempt to take a screenshot with that.

What actually happened?

Attempted to use an X11 function to grab the screen instead. (Image.core.grabscreen_x11(display_name))
Error:

❯ python3 piltest.py
Traceback (most recent call last):
  File "/home/henry/Projects/piltest.py", line 3, in <module>
    ImageGrab.grab()
    ~~~~~~~~~~~~~~^^
  File "/home/henry/Projects/dfScreenCap/venv/lib/python3.13/site-packages/PIL/ImageGrab.py", line 78, in grab
    size, data = Image.core.grabscreen_x11(display_name)
                 ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
OSError: X get_image failed: error 8 (73, 0, 853)

What are your OS, Python and Pillow versions?

  • OS: Arch Linux (+ Hyprland)
  • Python: 3.13.6
  • Pillow: 11.1.0
--------------------------------------------------------------------
Pillow 11.1.0
Python 3.13.5 (main, Jun 21 2025, 09:35:00) [GCC 15.1.1 20250425]
--------------------------------------------------------------------
Python executable is /home/henry/Projects/dfScreenCap/venv/bin/python3
Environment Python files loaded from /home/henry/Projects/dfScreenCap/venv
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /home/henry/Projects/dfScreenCap/venv/lib/python3.13/site-packages/PIL
Binary Pillow modules loaded from /home/henry/Projects/dfScreenCap/venv/lib/python3.13/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 11.1.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.5.0
--- JPEG support ok, compiled for libjpeg-turbo 3.1.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.3
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1, compiled for zlib-ng 2.2.2
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.16, harfbuzz 10.1.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
# Run on Hyprland
from PIL import ImageGrab

ImageGrab.grab()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions