【发布时间】:2012-11-28 20:51:42
【问题描述】:
我试图使用 ipython notebook 。我安装了所有依赖库。但是,在启动 ipython 或 Ipython 控制台中的“savefig”函数时,我不能使用“--pylab=inline”选项。当我尝试执行其中任何一个时,由于执行 matplotlib,返回了一条错误消息“RuntimeError:无法创建写入结构”。此外,来自 notebookApp 提示的警告说“libpng 警告:应用程序使用 libpng-1.2.41 构建但使用 1.5.13 运行”。
但是,我安装了最新的 libpng(1.5.13),使用 pip uninstall 卸载了 matplotlib,并使用 pip install 重新安装了 matplotlib(在构建过程中,我可以看到 libpng1.5.13 用于构建 matplotlib)。
我的系统配置是Mac OS X10.6,python2.7。有没有人有类似的经历或者给点建议?
以下是回溯错误:
[<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
非常感谢,
杰
【问题讨论】:
-
LD_LIBRARY_PATH 设置可能是您的问题。它可能是 matplotlib 使用的另一个库,它实际上是用 1.2.41 构建的。另外,您可以编辑您的帖子并复制粘贴完整回溯吗?
-
我使用了 export LD_LIBRARY_PATH="/opt/local/$LD_LIBRARY_PATH"(/opt/local/ 是我找到 libpng15 的位置),但没有任何区别。
-
不应该是
LD_LIBRARY_PATH=/opt/local/lib:$LD_LIBRARY_PATH吗?但我怀疑你的问题也可能出在其他地方。你能从 IPython 之外的 matplotlib 中保存 pngs 吗?例如,来自简单脚本或来自默认 Python 提示符?
标签: python matplotlib ipython libpng ipython-notebook