ipython notebook 的 matplotlib 和 libpng 问题 [英] matplotlib and libpng issues with ipython notebook

查看:30
本文介绍了ipython notebook 的 matplotlib 和 libpng 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 ipython notebook .我安装了所有的依赖库.但是,在 Ipython 控制台中启动 ipython 或savefig"函数时,我无法使用--pylab=inline"选项.当我尝试执行其中任何一个时,由于执行 matplotlib,返回了一条错误消息RuntimeError:无法创建写入结构".此外,notebookApp 提示中的警告说libpng 警告:应用程序使用 libpng-1.2.41 构建,但使用 1.5.13 运行".

I was trying to use ipython notebook . I installed all the dependency libraries. However, I cannot use either the "--pylab=inline" option when launching ipython or "savefig" function in the Ipython console. When I tried to do either of them, an error message was returned "RuntimeError: Could not create write struct" resulting from execution of matplotlib. Also, a warning from the notebookApp prompt said "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).

However, I installed the newest libpng(1.5.13), uninstalled matplotlib with pip uninstall and reinstalled matplotlib with pip install (and during the build process, I can see that libpng1.5.13 is used for the building of matplotlib).

我的系统配置是Mac OS X10.6,python2.7.有没有人有类似的经历或一些建议?

The configuration for my system is Mac OS X10.6, python2.7. Anybody has similar experience or some suggestiongs?

以下是回溯错误:

[<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

非常感谢,

推荐答案

我在 OS X Mavericks 上遇到了同样的问题,我通过自制软件安装了 libpng 并安装了 XQuartz.结果证明 matplotlib 在编译时找到了较旧的 XQuartz libpng 版本,但在运行时找到了更新的自制 libpng.

I had this same problem on OS X Mavericks with libpng installed via homebrew and also XQuartz installed. It turned out matplotlib was finding the older XQuartz libpng version when compiling, but finding the more recent homebrew libpng at runtime.

我发现的最佳解决方案来自 jaengelberg 在 github 上的评论:卸载matplotlib,临时重命名 XQuartz libpng 头文件,使其无法被找到,安装 matplotlib,然后将头文件名称改回来.

The best solution I've found is from this comment by jaengelberg on github: Uninstall matplotlib, temporarily rename the XQuartz libpng headers so they can't be found, install matplotlib, then change the header names back.

这里是完整的:

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

这篇关于ipython notebook 的 matplotlib 和 libpng 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆