Skip to content

Commit ea40d72

Browse files
authored
Merge pull request matplotlib#30657 from heinrich5991/pr_attributeerror_gi_require_version
Fix `AttributeError: module 'gi' has no attribute 'require_version'`
2 parents 9b61b47 + 3ecf087 commit ea40d72

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
CloseEvent, KeyEvent, LocationEvent, MouseEvent, ResizeEvent)
1111

1212
try:
13-
import gi
13+
from gi import require_version as gi_require_version
1414
except ImportError as err:
1515
raise ImportError("The GTK3 backends require PyGObject") from err
1616

1717
try:
1818
# :raises ValueError: If module/version is already loaded, already
1919
# required, or unavailable.
20-
gi.require_version("Gtk", "3.0")
20+
gi_require_version("Gtk", "3.0")
2121
# Also require GioUnix to avoid PyGIWarning when Gio is imported
2222
# GioUnix is platform-specific and may not be available on all systems
2323
try:
24-
gi.require_version("GioUnix", "2.0")
24+
gi_require_version("GioUnix", "2.0")
2525
except ValueError:
2626
# GioUnix is not available on this platform, which is fine
2727
pass

lib/matplotlib/backends/backend_gtk4.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
KeyEvent, LocationEvent, MouseEvent, ResizeEvent, CloseEvent)
1010

1111
try:
12-
import gi
12+
from gi import require_version as gi_require_version
1313
except ImportError as err:
1414
raise ImportError("The GTK4 backends require PyGObject") from err
1515

1616
try:
1717
# :raises ValueError: If module/version is already loaded, already
1818
# required, or unavailable.
19-
gi.require_version("Gtk", "4.0")
19+
gi_require_version("Gtk", "4.0")
2020
# Also require GioUnix to avoid PyGIWarning when Gio is imported
2121
# GioUnix is platform-specific and may not be available on all systems
2222
try:
23-
gi.require_version("GioUnix", "2.0")
23+
gi_require_version("GioUnix", "2.0")
2424
except ValueError:
2525
# GioUnix is not available on this platform, which is fine
2626
pass
@@ -29,6 +29,7 @@
2929
# auto-backend selection logic correctly skips.
3030
raise ImportError(e) from e
3131

32+
import gi
3233
from gi.repository import Gio, GLib, Gtk, Gdk, GdkPixbuf
3334
from . import _backend_gtk
3435
from ._backend_gtk import ( # noqa: F401 # pylint: disable=W0611

0 commit comments

Comments
 (0)