Skip to content

Commit e60c06a

Browse files
authored
Delay import from matplotlib_inline.backend_inline (#14330)
Possible fix for #14329. With this change, the reproducers from the issue become: ```python $ ipython <snip> In [1]: import matplotlib.pyplot as plt; plt.set_loglevel("debug") In [2]: %matplotlib tk DEBUG:matplotlib.pyplot:Loaded backend TkAgg version 8.6. ``` It is still possible to call `matplotlib.pyplot.switch_backend` twice but only if you request `%matplotlib inline`, and the `switch_backend` is called with same correct backend twice. This isn't ideal but it doesn't cause any problems apart from being a little slower than necessary.
2 parents e2c1309 + 08c6d12 commit e60c06a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎IPython/core/interactiveshell.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,8 +3654,6 @@ def enable_matplotlib(self, gui=None):
36543654
make sense in all contexts, for example a terminal ipython can't
36553655
display figures inline.
36563656
"""
3657-
from matplotlib_inline.backend_inline import configure_inline_support
3658-
36593657
from IPython.core import pylabtools as pt
36603658
gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
36613659

@@ -3670,6 +3668,9 @@ def enable_matplotlib(self, gui=None):
36703668
gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
36713669

36723670
pt.activate_matplotlib(backend)
3671+
3672+
from matplotlib_inline.backend_inline import configure_inline_support
3673+
36733674
configure_inline_support(self, backend)
36743675

36753676
# Now we must activate the gui pylab wants to use, and fix %run to take

0 commit comments

Comments
 (0)