Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Manually register the Matplotlib inline backend in case it hasn't #517

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading