use*_*353 10 python matplotlib ipython libpng ipython-notebook
我试图使用ipython笔记本.我安装了所有依赖库.但是,在Ipython控制台中启动ipython或"savefig"功能时,我无法使用"--pylab = inline"选项.当我尝试执行其中任何一个时,由于执行matplotlib而返回错误消息"RuntimeError:无法创建写入结构".此外,来自notebookApp提示的警告说"libpng警告:使用libpng-1.2.41构建的应用程序,但运行1.5.13".
但是,我安装了最新的libpng(1.5.13),卸载了pp卸载的matplotlib,并重新安装了pp 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
Run Code Online (Sandbox Code Playgroud)
非常感谢,
杰
我在OS X Mavericks上遇到了同样的问题,通过自制软件安装libpng并安装了XQuartz.事实证明,matplotlib在编译时发现了较旧的XQuartz libpng版本,但在运行时找到了更新的自制libpng.
我发现的最佳解决方案是jaengelberg在github上发表的评论:卸载matplotlib,暂时重命名XQuartz libpng标头,使其无法找到,安装matplotlib,然后更改标题名称.
这里是完整的:
pip uninstall matplotlib
cd /opt/X11/include/libpng15
sudo mv png.h _png.h
sudo mv pngconf.h _pngconf.h
sudo mv pnglibconf.h _pnglibconf.h
pip install matplotlib
sudo mv _png.h png.h
sudo mv _pngconf.h pngconf.h
sudo mv _pnglibconf.h pnglibconf.h
Run Code Online (Sandbox Code Playgroud)
也许它在运行时加载了错误的 libpng 。如果您针对 libpng 1.5 构建了 matplotlib,请确保您也使用它运行。libpng 1.2 和 1.5 不兼容。
在 shell 中,您可以设置 DYLD_LIBRARY_PATH 来更改链接器首先搜索库的位置。
otool -L /<somepath>/matplotlib/_png.so
Run Code Online (Sandbox Code Playgroud)
应该告诉你 matplotlib 在运行时发现了什么。