Skip to content

Commit

Permalink
Backport PR #517: PR: Manually register the Matplotlib inline backend…
Browse files Browse the repository at this point in the history
… in case it wasn't
  • Loading branch information
ccordoba12 authored and meeseeksmachine committed Oct 12, 2024
1 parent cb12eda commit 3004cc5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spyder_kernels/console/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,33 @@ def enable_matplotlib(self, gui=None):
enabled_gui = "inline"
gui = enabled_gui

# Check if the inline backend is registered. It should be at this
# point, but sometimes that can fail due to a mismatch between
# the installed versions of IPython, matplotlib and matplotlib-inline.
# Fixes spyder-ide/spyder#22420.
if gui == "inline":
is_inline_registered = False

# The flush_figures callback should be listed as a post_execute
# event if the backend was registered successfully.
for event in self.events.callbacks["post_execute"]:
if "matplotlib_inline.backend_inline.flush_figures" in repr(
event
):
is_inline_registered = True
break

# Manually register the backend in case it wasn't
if not is_inline_registered:
from IPython.core.pylabtools import activate_matplotlib
from matplotlib_inline.backend_inline import (
configure_inline_support
)

backend = "module://matplotlib_inline.backend_inline"
activate_matplotlib(backend)
configure_inline_support(self, backend)

# To easily track the current interactive backend
if self.kernel.interactive_backend is None:
self.kernel.interactive_backend = gui if gui != "inline" else None
Expand Down

0 comments on commit 3004cc5

Please sign in to comment.