Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite62d9fa

Browse files
committed
Merge pull request#5038 from tacaswell/prf_fix_import_time
PRF: only try IPython if it is already imported
2 parentse01241c +bc20fe2 commite62d9fa

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

‎lib/matplotlib/pyplot.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def _backend_selection():
112112
_IP_REGISTERED=None
113113
_INSTALL_FIG_OBSERVER=False
114114

115+
115116
definstall_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-
fromIPythonimportget_ipython
132-
ip=get_ipython()
133-
ifipisNone:
134-
raise_NotIPython()
135-
136-
if_IP_REGISTERED:
137-
return
138-
139-
defpost_execute():
140-
ifmatplotlib.is_interactive():
141-
draw_all()
142-
143-
# IPython >= 2
144-
try:
145-
ip.events.register('post_execute',post_execute)
146-
exceptAttributeError:
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'insys.modules:
133+
fromIPythonimportget_ipython
134+
ip=get_ipython()
135+
ifipisNone:
136+
raise_NotIPython()
137+
138+
if_IP_REGISTERED:
139+
return
140+
141+
defpost_execute():
142+
ifmatplotlib.is_interactive():
143+
draw_all()
144+
145+
# IPython >= 2
146+
try:
147+
ip.events.register('post_execute',post_execute)
148+
exceptAttributeError:
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):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp