File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,33 @@ def enable_matplotlib(self, gui=None):
101
101
enabled_gui = "inline"
102
102
gui = enabled_gui
103
103
104
+ # Check if the inline backend is registered. It should be at this
105
+ # point, but sometimes that can fail due to a mismatch between
106
+ # the installed versions of IPython, matplotlib and matplotlib-inline.
107
+ # Fixes spyder-ide/spyder#22420.
108
+ if gui == "inline" :
109
+ is_inline_registered = False
110
+
111
+ # The flush_figures callback should be listed as a post_execute
112
+ # event if the backend was registered successfully.
113
+ for event in self .events .callbacks ["post_execute" ]:
114
+ if "matplotlib_inline.backend_inline.flush_figures" in repr (
115
+ event
116
+ ):
117
+ is_inline_registered = True
118
+ break
119
+
120
+ # Manually register the backend in case it wasn't
121
+ if not is_inline_registered :
122
+ from IPython .core .pylabtools import activate_matplotlib
123
+ from matplotlib_inline .backend_inline import (
124
+ configure_inline_support
125
+ )
126
+
127
+ backend = "module://matplotlib_inline.backend_inline"
128
+ activate_matplotlib (backend )
129
+ configure_inline_support (self , backend )
130
+
104
131
# To easily track the current interactive backend
105
132
if self .kernel .interactive_backend is None :
106
133
self .kernel .interactive_backend = gui if gui != "inline" else None
You can’t perform that action at this time.
0 commit comments