File tree Expand file tree Collapse file tree 1 file changed +25
-21
lines changed Expand file tree Collapse file tree 1 file changed +25
-21
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ def _backend_selection():
112
112
_IP_REGISTERED = None
113
113
_INSTALL_FIG_OBSERVER = False
114
114
115
+
115
116
def install_repl_displayhook ():
116
117
"""
117
118
Install a repl display hook so that any stale figure are automatically
@@ -128,27 +129,30 @@ class _NotIPython(Exception):
128
129
# see if we have IPython hooks around, if use them
129
130
130
131
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
+
A239
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
152
156
153
157
# import failed or ipython is not running
154
158
except (ImportError , _NotIPython ):
You can’t perform that action at this time.
0 commit comments