diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 888f5a770f5d..4e05119aa0f6 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -18,6 +18,13 @@ # :raises ValueError: If module/version is already loaded, already # required, or unavailable. gi.require_version("Gtk", "3.0") + # Also require GioUnix to avoid PyGIWarning when Gio is imported + # GioUnix is platform-specific and may not be available on all systems + try: + gi.require_version("GioUnix", "2.0") + except ValueError: + # GioUnix is not available on this platform, which is fine + pass except ValueError as e: # in this case we want to re-raise as ImportError so the # auto-backend selection logic correctly skips. diff --git a/lib/matplotlib/backends/backend_gtk4.py b/lib/matplotlib/backends/backend_gtk4.py index cd38968779ed..a45fa0bc490f 100644 --- a/lib/matplotlib/backends/backend_gtk4.py +++ b/lib/matplotlib/backends/backend_gtk4.py @@ -17,6 +17,13 @@ # :raises ValueError: If module/version is already loaded, already # required, or unavailable. gi.require_version("Gtk", "4.0") + # Also require GioUnix to avoid PyGIWarning when Gio is imported + # GioUnix is platform-specific and may not be available on all systems + try: + gi.require_version("GioUnix", "2.0") + except ValueError: + # GioUnix is not available on this platform, which is fine + pass except ValueError as e: # in this case we want to re-raise as ImportError so the # auto-backend selection logic correctly skips.