Intro

TL;DR: need to plot 3d data, using matplotlib

I’ve been working on a python module for dealing with tables of data, basically it ends up being a big list of namedtuples with some helper methods. I’ll post it later.

To test it, I wanted to work with a big dataset, so I decided that now was finally the time to play with radiohead’s “House of Cards” LIDAR data.

Naturally I got to the point where I wanted to plot stuff. That’s where matplotlib comes in.

The Problem

Simply, the problem is “ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib/_png.so, 2): Symbol not found: _png_create_info_struct”, as seen in this traceback:

Traceback (most recent call last):
  File "./plottest.py", line 3, in 
    from matplotlib import pyplot
  File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 26, in 
    from matplotlib.figure import Figure, figaspect
  File "/Library/Python/2.7/site-packages/matplotlib/figure.py", line 32, in 
    from matplotlib.image import FigureImage
  File "/Library/Python/2.7/site-packages/matplotlib/image.py", line 22, in 
    import matplotlib._png as _png
ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib/_png.so, 2): Symbol not found: _png_create_info_struct
  Referenced from: /Library/Python/2.7/site-packages/matplotlib/_png.so
  Expected in: flat namespace
 in /Library/Python/2.7/site-packages/matplotlib/_png.so

Or maybe you have something like “ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: /usr/local/lib/libpng15.15.dylib”, as seen in this traceback:

Traceback (most recent call last):
  File "./plottest.py", line 3, in 
    from matplotlib import pyplot
  File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 26, in 
    from matplotlib.figure import Figure, figaspect
  File "/Library/Python/2.7/site-packages/matplotlib/figure.py", line 32, in 
    from matplotlib.image import FigureImage
  File "/Library/Python/2.7/site-packages/matplotlib/image.py", line 22, in 
    import matplotlib._png as _png
ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: /usr/local/lib/libpng15.15.dylib
  Referenced from: /Library/Python/2.7/site-packages/matplotlib/_png.so
  Reason: no suitable image found.  Did find:
	/usr/local/lib/libpng15.15.dylib: mach-o, but wrong architecture
	/usr/local/lib/libpng15.15.dylib: mach-o, but wrong architecture

The Solution

This is essentially the same problem/solution as the PIL pip/homebrew problem that I encountered earlier. Here are the steps to fix for matplotlib

sudo pip uninstall matplotlib # possibly optional for you
sudo rm -rf /tmp/pip-build-root/ # possibly optional for you
brew reinstall libpng --universal
brew reinstall freetype --universal
sudo pip install matplotlib