File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ def _backend_selection():
112112_IP_REGISTERED = None
113113_INSTALL_FIG_OBSERVER = False
114114
115+
115116def install_repl_displayhook ():
116117 """
117118 Install a repl display hook so that any stale figure are automatically
@@ -128,27 +129,30 @@ class _NotIPython(Exception):
128129 # see if we have IPython hooks around, if use them
129130
130131 try :
131- from IPython import get_ipython
132- ip = get_ipython ()
133- if ip is None :
134- raise _NotIPython ()
135-
136- if _IP_REGISTERED :
137- return
138-
139- def post_execute ():
140- if matplotlib .is_interactive ():
141- draw_all ()
142-
143- # IPython >= 2
144- try :
145- ip .events .register ('post_execute' , post_execute )
146- except AttributeError :
147- # IPython 1.x
148- ip .register_post_execute (post_execute )
149-
150- _IP_REGISTERED = post_execute
151- _INSTALL_FIG_OBSERVER = False
132+ if 'IPython' in sys .modules :
133+ from IPython import get_ipython
134+ ip = get_ipython ()
135+ if ip is None :
136+ raise _NotIPython ()
137+
138+ if _IP_REGISTERED :
139+ return
140+
141+ def post_execute ():
142+ if matplotlib .is_interactive ():
143+ draw_all ()
144+
145+ # IPython >= 2
146+ try :
147+ ip .events .register ('post_execute' , post_execute )
148+ except AttributeError :
149+ # IPython 1.x
150+ ip .register_post_execute (post_execute )
151+
152+ _IP_REGISTERED = post_execute
153+ _INSTALL_FIG_OBSERVER = False
154+ else :
155+ _INSTALL_FIG_OBSERVER = True
152156
153157 # import failed or ipython is not running
154158 except (ImportError , _NotIPython ):
You can’t perform that action at this time.
0 commit comments