Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 236355c

Browse files
wmanleypelson
authored andcommitted
pyplot: Fix exception in _backend_selection during import
if the new style introspection GObject python bindings are in use. With pygobject >= 3.13.4 the following: from gi.repository import GObject from matplotlib import pyplot causes an exception to be raised: > AttributeError: When using gi.repository you must not import static modules > like "gobject". Please change all occurrences of "import gobject" to "from > gi.repository import GObject". See: > https://bugzilla.gnome.org/show_bug.cgi?id=709183 It is not valid to use both non-introspection based and introspection based PyGObject in the same process. Backend probing will `import gobject` (i.e. the non-introspection bindings) if it sees that the 'gtk' module is loaded. Unfortunately it wouldn't check if this was the pygi or old-style gtk module. This commit adds this check avoiding the exception. This check was added to PyGObject in [d704033][1] [1]: https://git.gnome.org/browse/pygobject/commit/?id=d704033
1 parent f9feefe commit 236355c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/matplotlib/pyplot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ def _backend_selection():
9191
if not PyQt5.QtWidgets.qApp.startingUp():
9292
# The mainloop is running.
9393
rcParams['backend'] = 'qt5Agg'
94-
elif 'gtk' in sys.modules and not backend in ('GTK', 'GTKAgg',
95-
'GTKCairo'):
94+
elif ('gtk' in sys.modules
95+
and backend not in ('GTK', 'GTKAgg', 'GTKCairo')
96+
and 'gi.repository.GObject' not in sys.modules):
9697
import gobject
9798
if gobject.MainLoop().is_running():
9899
rcParams['backend'] = 'gtk' + 'Agg' * is_agg_backend

0 commit comments

Comments
 (0)