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

Skip to content

Commit 3ced029

Browse files
committed
FIX: be more careful about import gobject
if `gi` is imported, importing `gobject` will fail, but `gi.repository` might not be in `sys.modules`
1 parent e01241c commit 3ced029

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/matplotlib/pyplot.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,15 @@ def _backend_selection():
9292
if not PyQt5.QtWidgets.qApp.startingUp():
9393
# The mainloop is running.
9494
rcParams['backend'] = 'qt5Agg'
95-
elif ('gtk' in sys.modules
96-
and backend not in ('GTK', 'GTKAgg', 'GTKCairo')
97-
and 'gi.repository.GObject' not in sys.modules):
98-
import gobject
99-
if gobject.MainLoop().is_running():
95+
elif ('gtk' in sys.modules and
96+
backend not in ('GTK', 'GTKAgg', 'GTKCairo')):
97+
if 'gi' in sys.modules:
98+
from gi.repository import GObject
99+
ml = GObject.MainLoop
100+
else:
101+
import gobject
102+
ml = gobject.MainLoop
103+
if ml().is_running():
100104
rcParams['backend'] = 'gtk' + 'Agg' * is_agg_backend
101105
elif 'Tkinter' in sys.modules and not backend == 'TkAgg':
102106
# import Tkinter

0 commit comments

Comments
 (0)