【问题标题】:Matplotlib in IPython + Pandas: ImportError Symbol not found: _png_create_info_structIPython + Pandas 中的 Matplotlib:找不到 ImportError 符号:_png_create_info_struct
【发布时间】:2013-01-09 23:48:02
【问题描述】:

我在 Python 中构建了 Matplotlib,因此当我导入它或它的任何部分时,它可以正常工作并且图形也很好。

但是,当我运行以下内容时,我一直在阅读“用于数据分析的 Python”以及在 Ch.2 的 IPython 名称趋势演练中...

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

我明白了……

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

我在 Web 上找到的大多数修复程序都使用 Matplotlib 解决了 Python 中的问题,但在 IPython 中却没有。

下面是整个 IPython 输出:

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

【问题讨论】:

  • 您是否尝试过任何常规的 Python 修复?毕竟,这一切都在 Python 上运行。
  • 我实际上无法在普通 Python 中复制错误,因为引发错误的相同代码运行良好......!似乎是 IPython 或 IPython/pandas 问题。
  • 您使用的是哪个 MPL 后端? import matplotlib; print(matplotlib.rcParams['backend'])
  • 确保您对两者都使用相同的 Python:which pythonhead -n 1 $(which ipython)
  • 你的 python 和 ipython 版本交叉了吗?对我来说,这听起来像是安装错误和基于 mac 的路径问题的结合。也就是说,您针对一个版本的 python 编译和安装,并使用 ipython 运行另一个版本。

标签: python macos matplotlib pandas ipython


【解决方案1】:

我通过这个帖子找到了解决方案:ipython reads wrong python version

@minrk 关于which pythonwhich ipython 不匹配的观点导致我重写了我的/usr/local/bin/ipython 文件的第一行。

【讨论】:

    猜你喜欢
    • 2015-09-15
    • 2019-03-13
    • 2014-12-01
    • 2018-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    相关资源
    最近更新 更多