16

I used this guide to install the "scientific stack" for Python (OSX 10.9.2, brewed Python 2.7.6, IPython 2.0, matplotlib 1.3.1, libpng 1.6.10). Everything was looking good.

However, trying to run a simple plot in IPython's notebook environment with --pylab=inline gives me this error:

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/core/formatters.py:239: FormatterWarning: Exception in image/png formatter: Could not create write struct FormatterWarning,

And in the terminal it says: libpng warning: Application built with libpng-1.5.17 but running with 1.6.10

I have no other libpng installed as far as I can tell. I tried deleting all files beginning with libpng from /usr/local/ and reinstalling everything, to no avail. The output from building matplotlib (pip install matplotlib) contains:

BUILDING MATPLOTLIB
            matplotlib: yes [1.3.1]
                python: yes [2.7.6 (default, Mar 16 2014, 15:04:47)  [GCC
                        4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)]]
              platform: yes [darwin]

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [version 1.8.1]
              dateutil: yes [using dateutil version 2.2]
               tornado: yes [using tornado version 3.2]
             pyparsing: yes [using pyparsing version 2.0.1]
                 pycxx: yes [Couldn't import.  Using local copy.]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found. Using local copy.]
              freetype: yes [version 17.2.11]
                   png: yes [version 1.6.10]

OPTIONAL SUBPACKAGES
           sample_data: yes [installing]
              toolkits: yes [installing]
                 tests: yes [using nose version 1.3.1]

OPTIONAL BACKEND EXTENSIONS
                macosx: yes [installing, darwin]
                qt4agg: yes [installing, Qt: 4.8.6, PyQt4: 4.10.4]
               gtk3agg: no  [Requires pygobject to be installed.]
             gtk3cairo: no  [Requires cairo to be installed.]
                gtkagg: no  [Requires pygtk]
                 tkagg: yes [installing, version 81008]
                 wxagg: no  [requires wxPython]
                   gtk: no  [Requires pygtk]
                   agg: yes [installing]
                 cairo: no  [cairo not found]
             windowing: no  [Microsoft Windows only]

OPTIONAL LATEX DEPENDENCIES
                dvipng: no
           ghostscript: no
                 latex: no
               pdftops: no

So it seems to me matplotlib should be compiled against libpng 1.6.10? Can someone help me figure out what's going on?

MortenB
  • 193
  • 2
  • 7
  • I should perhaps add that the standard IPython terminal environment with MacOSX backend graphics works fine. – MortenB Apr 06 '14 at 18:50
  • Yes! Thanks! I had XQuartz installed with `/opt/X11/include/libpng15/png.h` and some others like that. Removing them and recompiling took care of my problem. – MortenB Apr 06 '14 at 21:49
  • For future reference: it may be easier to download something like [Anaconda](http://continuum.io/downloads), which installs the whole Scipy stack, rather than installing all of the pieces separately. – Thomas K Apr 06 '14 at 22:18
  • I'm having the same issue, can you specify exactly what you did please? – Spencer Apr 07 '14 at 04:39
  • 1
    I ran `sudo find / -name "png*.h"` to find the header files @Glenn mentioned. I noticed some in `/opt/X11`, which belongs to XQuartz. So I followed [this guide](http://xquartz.macosforge.org/trac/wiki/X11-UsersFAQ#UninstallSnowLeopardorLater) to remove XQuartz, and reinstalled matplotlib and ipython with pip. – MortenB Apr 07 '14 at 14:56
  • Thanks a lot. Same issue here. Running the process at http://xquartz.macosforge.org/trac/wiki/X11-UsersFAQ#UninstallSnowLeopardorLater and reinstalling matplotlib + ipython as noted above resolved the issue. Strange how everyone seems to be having the issue at the same time ... . – xbsd Apr 08 '14 at 03:20

4 Answers4

22

An expansion of the answer provided by @glenn-randers-pehrson:

pip uninstall matplotlib
cd /opt/X11/include/libpng15
mv png.h _png.h
mv pngconf.h _pngconf.h
mv pnglibconf.h _pnglibconf.h
pip install matplotlib
(if needed remove the old directory or use the force option)

(now move the .h files back to their original locations)
Jesse E.
  • 261
  • 1
  • 4
  • If you installed libpng via homebrew, and xquartz via brew cask, you can just temporary uninstall xquartz, install matplotlib (which will compile against homebrew's libpng, and then reinstall xquartz afterwards. – Ory Band May 10 '14 at 14:34
  • 1
    Is moving them back necessary? – Piotr Migdal Jun 17 '14 at 19:58
  • This solution worked for me, and I never bothered moving the .h files back to their original locations. – Meekohi Jul 15 '15 at 18:23
14

Look for old header files beginning with "png" (png.h, pngconf.h, perhaps others) and remove them.

Glenn Randers-Pehrson
  • 11,940
  • 3
  • 37
  • 61
9

For the sake of documentation (following on from above comments):

Remove X11

launchctl unload /Library/LaunchAgents/org.macosforge.xquartz.startx.plist
sudo launchctl unload /Library/LaunchDaemons/org.macosforge.xquartz.privileged_startx.plist
sudo rm -rf /opt/X11* /Library/Launch*/org.macosforge.xquartz.* /Applications/Utilities/XQuartz.app /etc/*paths.d/*XQuartz
sudo pkgutil --forget org.macosforge.xquartz.pkg

Then,

if you have matplotlib / python installed, run the following as appropriate:

pip uninstall matplotlib
pip uninstall ipython

Then,

pip install matplotlib
pip install ipython

If necessary, XQuartz can be re-installed from https://www.macupdate.com/app/mac/26593/xquartz.

[Note: This does re-add the /opt/X11/include/libpng15/png.h etc files, but ipython worked fine afterwards.]

xbsd
  • 2,438
  • 4
  • 25
  • 35
0

While it is a bit ridiculous having multiple copies of libpng around, this problem results from the path for the pip compiler and python being different. You could also fix this problem through the path, and then recompiling, but the above solutions work too.