Skip to content

Commit f9fc2f6

Browse files
authored
Merge pull request #517 from ccordoba12/fix-registering-inline-backend
PR: Manually register the Matplotlib inline backend in case it wasn't
2 parents 7056185 + d8855d4 commit f9fc2f6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

spyder_kernels/console/shell.py

+27
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,33 @@ def enable_matplotlib(self, gui=None):
101101
enabled_gui = "inline"
102102
gui = enabled_gui
103103

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+
104131
# To easily track the current interactive backend
105132
if self.kernel.interactive_backend is None:
106133
self.kernel.interactive_backend = gui if gui != "inline" else None

0 commit comments

Comments
 (0)