我尝试使用 IPython Notebook。我安装了所有必要的库,但在启动 IPython 时无法使用“--pylab = inline”选项或在 IPython 控制台中使用“savefig”函数。当我尝试执行它们之一时,会返回一个错误消息“RuntimeError:Could not create write struct”。这是由于 matplotlib 的执行导致的。此外,notebookApp 提示中的警告显示“libpng warning:Application built with libpng-1.2.41 but running with 1.5.13”。
然而,我安装了最新的 libpng(1.5.13),使用 pip uninstall 卸载了 matplotlib,并使用 pip install 重新安装了 matplotlib(在构建过程中,我可以看到使用 libpng1.5.13 来构建 matplotlib)。
我的系统配置是Mac OS X10.6、Python2.7。是否有人有类似的经验或建议?以下是 traceback 错误:
[<matplotlib.lines.Line2D at 0x106066d50>]
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/zmq/pylab/backend_inline.pyc in show(close)
100 try:
101 for figure_manager in Gcf.get_all_fig_managers():
--> 102 send_figure(figure_manager.canvas.figure)
103 finally:
104 show._to_draw = []
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/zmq/pylab/backend_inline.pyc in send_figure(fig)
209 """
210 fmt = InlineBackend.instance().figure_format
--> 211 data = print_figure(fig, fmt)
212 # print_figure will return None if there's nothing to draw:
213 if data is None:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt)
102 try:
103 bytes_io = BytesIO()
--> 104 fig.canvas.print_figure(bytes_io, format=fmt, bbox_inches='tight')
105 data = bytes_io.getvalue()
106 finally:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2050 orientation=orientation,
2051 dryrun=True,
-> 2052 **kwargs)
2053 renderer = self.figure._cachedRenderer
2054 bbox_inches = self.figure.get_tightbbox(renderer)
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
501 _png.write_png(renderer._renderer.buffer_rgba(),
502 renderer.width, renderer.height,
--> 503 filename_or_obj, self.figure.dpi)
504 finally:
505 if close:
RuntimeError: Could not create write struct
非常感谢,
Jie
LD_LIBRARY_PATH=/opt/local/lib:$LD_LIBRARY_PATH
吗?但我怀疑你的问题可能还存在其他地方。你能否在 IPython 之外保存 matplotlib 的 png 文件?例如,从一个简单的脚本或默认的 Python 提示符中? - user707650