Skip to content

Commit 3a7c48d

Browse files
committed
catch circular import error configuring matplotlib on import
only python 2 affected, caused by unnecessary imports in IPython pylabtools
1 parent f2ceb78 commit 3a7c48d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

backend_inline.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,17 @@ def flush_figures():
147147
def _enable_matplotlib_integration():
148148
"""Enable extra IPython matplotlib integration when we are loaded as the matplotlib backend."""
149149
from matplotlib import get_backend
150-
from IPython.core.pylabtools import configure_inline_support
151150
ip = get_ipython()
152151
backend = get_backend()
153152
if ip and backend == 'module://%s' % __name__:
154-
configure_inline_support(ip, backend)
153+
from IPython.core.pylabtools import configure_inline_support
154+
try:
155+
configure_inline_support(ip, backend)
156+
except ImportError:
157+
# bugs may cause a circular import on Python 2
158+
def configure_once(*args):
159+
configure_inline_support(ip, backend)
160+
ip.events.unregister('post_run_cell', configure_once)
161+
ip.events.register('post_run_cell', configure_once)
155162

156163
_enable_matplotlib_integration()

0 commit comments

Comments
 (0)