matplotlib and libpng issues with ipython notebook

痴心易碎 提交于 2019-11-29 06:34:05

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.

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.

Here it is in full:

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

I had this same problem while trying to view images from OpenCV in the Jupyter Notebook while working in an Anaconda environment. Forcing a reinstall of matplotlib worked for me:

pip install -U --force-reinstall matplotlib

I found this method while looking at this GitHub link from Matt's solution.

For me putting

%matplotlib inline

before all matplotlib imports resolved this issue

I had this problem as well. Another solution is to change the format which the notebook will render images in, from 'png' to 'svg'. This can be done in your config file. Mine is located at:

~/.ipython/profile_default/ipython_notebook_config.py

There is a line that looks like this

# c.InlineBackend.figure_format = 'png'

Uncommenting and changing to 'svg' did the trick for me:

c.InlineBackend.figure_format = 'svg'

maybe its loading the wrong libpng at runtime. If you built matplotlib against libpng 1.5 make sure you also run with it. libpng 1.2 and 1.5 are not compatible.

in a shell you can set DYLD_LIBRARY_PATH to change the location the linker searches for libraries first.

otool -L /<somepath>/matplotlib/_png.so

should tell you what matplotlib is finding at runtime.

Osteoboon

I had almost the exact same experience:

  • Exactly the same "RuntimeError: Could not create write struct" in IPython Notebook
  • Exactly the same "libpng warning: Application built with libpng-1.2.41 but running with 1.5.13"
  • Same OS: Mac OS X10.6
  • py33-ipython @0.13.1_0+notebook+parallel (from MacPorts)
  • python3.3 (from MacPorts) in place of your python2.7 (only diff I see from you)

I think the MacPorts recipe for IPython may have some problems for some OS versions.

Not sure where you got your python2.7 from, but my solution was that I ultimately ditched MacPorts in favor of homebrew (which also had some problems, but I was able to resolve them by installing some packages directly from sources, see this question).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!