diff --git a/IPython/core/pylabtools.py b/IPython/core/pylabtools.py index 4423ed5..d42c088 100644 --- a/IPython/core/pylabtools.py +++ b/IPython/core/pylabtools.py @@ -310,12 +310,12 @@ def activate_matplotlib(backend): # magic of switch_backend(). matplotlib.rcParams['backend'] = backend - import matplotlib.pyplot - matplotlib.pyplot.switch_backend(backend) + # Due to circular imports, pyplot may be only partially initialised + # when this function runs. + # So avoid needing matplotlib attribute-lookup to access pyplot. + from matplotlib import pyplot as plt - # This must be imported last in the matplotlib series, after - # backend/interactivity choices have been made - import matplotlib.pyplot as plt + plt.switch_backend(backend) plt.show._needmain = False # We need to detect at runtime whether show() is called by the user. diff --git a/IPython/sphinxext/ipython_directive.py b/IPython/sphinxext/ipython_directive.py index 60c1b51..0481624 100644 --- a/IPython/sphinxext/ipython_directive.py +++ b/IPython/sphinxext/ipython_directive.py @@ -585,7 +585,7 @@ class EmbeddedSphinxShell(object): if self.warning_is_error: raise RuntimeError('Non Expected warning in `{}` line {}'.format(filename, lineno)) - self.cout.truncate(0) + self.clear_cout() return (ret, input_lines, processed_output, is_doctest, decorator, image_file, image_directive)