1

I've built Matplotlib in Python such that when I import it or any part of it, it works fine and graphs fine.

However, I've been going through "Python for Data Analysis," and in Ch.2's IPython walkthrough of name trends, when I run the following...

total_births.plot(title='Total births by sex and year')

I get...

ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib/_png.so, 2): Symbol not found: _png_create_info_struct

Most of the fixes I've found around the Web solve the issue in Python with Matplotlib but not in IPython in particular.

Below is the entire IPython output:

ImportError                               Traceback (most recent call last)
<ipython-input-27-08d014b1a776> in <module>()
----> 1 total_births.plot(title='Total births by sex and year')

/Library/Python/2.7/site-packages/pandas/tools/plotting.pyc in plot_frame(frame, x, y,     subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, style, title, xlim, ylim, logx, logy, xticks, yticks, kind, sort_columns, fontsize, secondary_y, **kwds)
   1453                      logy=logy, sort_columns=sort_columns,
   1454                      secondary_y=secondary_y, **kwds)
-> 1455     plot_obj.generate()
   1456     plot_obj.draw()
   1457     if subplots:

/Library/Python/2.7/site-packages/pandas/tools/plotting.pyc in generate(self)
    732         self._args_adjust()
    733         self._compute_plot_data()
--> 734         self._setup_subplots()
    735         self._make_plot()
    736         self._post_plot_logic()

/Library/Python/2.7/site-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
    781         else:
    782             if self.ax is None:
--> 783                 fig = self.plt.figure(figsize=self.figsize)
    784                 ax = fig.add_subplot(111)
    785                 ax = self._maybe_right_yaxis(ax)

/Library/Python/2.7/site-packages/pandas/lib.so in pandas.lib.cache_readonly.__get__ (pandas/lib.c:27324)()

/Library/Python/2.7/site-packages/pandas/tools/plotting.pyc in plt(self)
    859     @cache_readonly
    860     def plt(self):
--> 861         import matplotlib.pyplot as plt
    862         return plt
    863 

/Library/Python/2.7/site-packages/matplotlib/pyplot.py in <module>()
     24 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
     25 from matplotlib import docstring
---> 26 from matplotlib.figure import Figure, figaspect
     27 from matplotlib.backend_bases import FigureCanvasBase
     28 from matplotlib.image import imread as _imread

/Library/Python/2.7/site-packages/matplotlib/figure.py in <module>()
     30 
     31 from matplotlib import _image
---> 32 from matplotlib.image import FigureImage
     33 
     34 import matplotlib.colorbar as cbar

    /Library/Python/2.7/site-packages/matplotlib/image.py in <module>()
         20 # For clarity, names from _image are given explicitly in this module:
         21 import matplotlib._image as _image
    ---> 22 import matplotlib._png as _png
         23 
         24 # For user convenience, the names from _image are also imported into

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
tacaswell
  • 84,579
  • 22
  • 210
  • 199
alxlvt
  • 675
  • 2
  • 10
  • 18
  • Have you tried any of the general Python fixes? It's all running on Python, after all. – Thomas K Jan 25 '13 at 23:23
  • I can't actually replicate the error in normal Python, as the same code that throws the error is working perfectly fine...! Seems to be either an IPython or IPython/pandas issue. – alxlvt Jan 26 '13 at 00:00
  • Which MPL backend are you using? `import matplotlib; print(matplotlib.rcParams['backend'])` – Paul H Jan 26 '13 at 01:10
  • make sure you are using the same Python for both: `which python` and `head -n 1 $(which ipython)` – minrk Jan 26 '13 at 01:54
  • Do you have your python and ipython versions crossed? This smells like a combination of install errors and mac-based path issues to me. That is, you compiled and installed against one version of python, and are running a different version with ipython. – tacaswell Jan 26 '13 at 03:13
  • echoing @minrk, check which version of python each is pointing at. in both python and iPython run the command "import sys; print sys.version" – Mike Jan 26 '13 at 03:28
  • @tcaswell Yes, a Mac. @Paul H MacOSX @Mike Both python and ipython point to the same: 2.7.2. @minrk I get the following, which are different, so maybe that's what's up? `$ which python` `/Library/Frameworks/Python.framework/Versions/2.7/bin/python` `$ head -n 1 $(which ipython)` `#!/usr/bin/python` – alxlvt Jan 26 '13 at 22:51

1 Answers1

1

I found a solution via this thread: ipython reads wrong python version

@minrk's point about the non-matching between which python and which ipython led me to rewrite the first line of my /usr/local/bin/ipython file.

Community
  • 1
  • 1
alxlvt
  • 675
  • 2
  • 10
  • 18