From 918f7ee93bdf25ec7b8dbf2220fb05d3f304a885 Mon Sep 17 00:00:00 2001 From: LangQi99 <2032771946@qq.com> Date: Tue, 9 Sep 2025 10:05:46 +0800 Subject: [PATCH 1/2] fix import warning --- lib/matplotlib/backends/backend_gtk3.py | 2 ++ lib/matplotlib/backends/backend_gtk4.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 888f5a770f5d..38c1541b8df1 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -18,6 +18,8 @@ # :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 + gi.require_version("GioUnix", "2.0") 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..ec45c1f5b205 100644 --- a/lib/matplotlib/backends/backend_gtk4.py +++ b/lib/matplotlib/backends/backend_gtk4.py @@ -17,6 +17,8 @@ # :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 + gi.require_version("GioUnix", "2.0") except ValueError as e: # in this case we want to re-raise as ImportError so the # auto-backend selection logic correctly skips. From 2bef93f32f15fcfad77de3c8530731d84f7516cf Mon Sep 17 00:00:00 2001 From: LangQi99 <2032771946@qq.com> Date: Tue, 9 Sep 2025 10:33:53 +0800 Subject: [PATCH 2/2] fix --- lib/matplotlib/backends/backend_gtk3.py | 7 ++++++- lib/matplotlib/backends/backend_gtk4.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 38c1541b8df1..4e05119aa0f6 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -19,7 +19,12 @@ # required, or unavailable. gi.require_version("Gtk", "3.0") # Also require GioUnix to avoid PyGIWarning when Gio is imported - gi.require_version("GioUnix", "2.0") + # 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 ec45c1f5b205..a45fa0bc490f 100644 --- a/lib/matplotlib/backends/backend_gtk4.py +++ b/lib/matplotlib/backends/backend_gtk4.py @@ -18,7 +18,12 @@ # required, or unavailable. gi.require_version("Gtk", "4.0") # Also require GioUnix to avoid PyGIWarning when Gio is imported - gi.require_version("GioUnix", "2.0") + # 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.