当前位置: 代码迷 >> python >> 导入 matplotlib._png 失败
  详细解决方案

导入 matplotlib._png 失败

热度:52   发布时间:2023-06-14 08:57:52.0

我在让matplotlib 1.0.0Python 2.5.2 ( Ubuntu 10.04 ) 中工作时遇到问题,请参阅附加的控制台输出。 任何想法表示赞赏。 谢谢

Python 2.5.2 (r252:60911, Jul 23 2010, 23:04:44) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> import matplotlib
>>> print matplotlib.__version__
1.0.0
>>> print numpy.__version__     
1.4.1
>>> print scipy.__version__
0.8.0rc3

>>> from pylab import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.5/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/usr/local/lib/python2.5/site-packages/matplotlib/pylab.py", line 216, in <module>
    from matplotlib import mpl  # pulls in most modules
  File "/usr/local/lib/python2.5/site-packages/matplotlib/mpl.py", line 2, in <module>
    from matplotlib import axis
  File "/usr/local/lib/python2.5/site-packages/matplotlib/axis.py", line 14, in <module>
    import matplotlib.text as mtext
  File "/usr/local/lib/python2.5/site-packages/matplotlib/text.py", line 31, in <module>
    from matplotlib.backend_bases import RendererBase
  File "/usr/local/lib/python2.5/site-packages/matplotlib/backend_bases.py", line 41, in <module>
    import matplotlib.textpath as textpath
  File "/usr/local/lib/python2.5/site-packages/matplotlib/textpath.py", line 9, in <module>
    from matplotlib.mathtext import MathTextParser
  File "/usr/local/lib/python2.5/site-packages/matplotlib/mathtext.py", line 52, in <module>
    import matplotlib._png as _png
ImportError: libpng14.so.14: cannot open shared object file: No such file or directory
>>> 

七月 27,01:05 重建 matlibplot 给出:

sudo python setup.py build

basedirlist is: ['/usr/local', '/usr']
============================================================================
BUILDING MATPLOTLIB
            matplotlib: 1.0.0
                python: 2.5.2 (r252:60911, Jul 23 2010, 23:04:44)  [GCC
                        4.4.3]
              platform: linux2

REQUIRED DEPENDENCIES
                 numpy: 1.4.1
             freetype2: 11.1.5

OPTIONAL BACKEND DEPENDENCIES
                libpng: 1.4.3
               Tkinter: no
                        * TKAgg requires Tkinter
              wxPython: no
                        * wxPython not found
                  Gtk+: no
                        * Building for Gtk+ requires pygtk; you must be able
                        * to "import gtk" in your build/install environment
       Mac OS X native: no
                    Qt: no
                   Qt4: no
                 Cairo: no

OPTIONAL DATE/TIMEZONE DEPENDENCIES
              datetime: present, version unknown
              dateutil: 1.5
                  pytz: 2010h

OPTIONAL USETEX DEPENDENCIES
                dvipng: no
           ghostscript: 8.71
                 latex: no
               pdftops: 0.12.4

[Edit setup.cfg to suppress the above messages]
============================================================================
pymods ['pylab']
packages ['matplotlib', 'matplotlib.backends', 'matplotlib.backends.qt4_editor', 'matplotlib.projections', 'matplotlib.testing', 'matplotlib.testing.jpl_units', 'matplotlib.tests', 'mpl_toolkits', 'mpl_toolkits.mplot3d', 'mpl_toolkits.axes_grid', 'mpl_toolkits.axes_grid1', 'mpl_toolkits.axisartist', 'matplotlib.sphinxext', 'matplotlib.numerix', 'matplotlib.numerix.mlab', 'matplotlib.numerix.ma', 'matplotlib.numerix.linear_algebra', 'matplotlib.numerix.random_array', 'matplotlib.numerix.fft', 'matplotlib.tri', 'matplotlib.delaunay']
running build
running build_py
copying lib/matplotlib/mpl-data/matplotlibrc -> build/lib.linux-i686-2.5/matplotlib/mpl-data
copying lib/matplotlib/mpl-data/matplotlib.conf -> build/lib.linux-i686-2.5/matplotlib/mpl-data
running build_ext



sudo python setup.py install
basedirlist is: ['/usr/local', '/usr']
============================================================================
BUILDING MATPLOTLIB
            matplotlib: 1.0.0
                python: 2.5.2 (r252:60911, Jul 23 2010, 23:04:44)  [GCC
                        4.4.3]
              platform: linux2

REQUIRED DEPENDENCIES
                 numpy: 1.4.1
             freetype2: 11.1.5

OPTIONAL BACKEND DEPENDENCIES
                libpng: 1.4.3
               Tkinter: no
                        * TKAgg requires Tkinter
              wxPython: no
                        * wxPython not found
                  Gtk+: no
                        * Building for Gtk+ requires pygtk; you must be able
                        * to "import gtk" in your build/install environment
       Mac OS X native: no
                    Qt: no
                   Qt4: no
                 Cairo: no

OPTIONAL DATE/TIMEZONE DEPENDENCIES
              datetime: present, version unknown
              dateutil: 1.5
                  pytz: 2010h

OPTIONAL USETEX DEPENDENCIES
                dvipng: no
           ghostscript: 8.71
                 latex: no
               pdftops: 0.12.4

[Edit setup.cfg to suppress the above messages]
============================================================================
pymods ['pylab']
packages ['matplotlib', 'matplotlib.backends', 'matplotlib.backends.qt4_editor', 'matplotlib.projections', 'matplotlib.testing', 'matplotlib.testing.jpl_units', 'matplotlib.tests', 'mpl_toolkits', 'mpl_toolkits.mplot3d', 'mpl_toolkits.axes_grid', 'mpl_toolkits.axes_grid1', 'mpl_toolkits.axisartist', 'matplotlib.sphinxext', 'matplotlib.numerix', 'matplotlib.numerix.mlab', 'matplotlib.numerix.ma', 'matplotlib.numerix.linear_algebra', 'matplotlib.numerix.random_array', 'matplotlib.numerix.fft', 'matplotlib.tri', 'matplotlib.delaunay']
running install
running build
running build_py
copying lib/matplotlib/mpl-data/matplotlibrc -> build/lib.linux-i686-2.5/matplotlib/mpl-data
copying lib/matplotlib/mpl-data/matplotlib.conf -> build/lib.linux-i686-2.5/matplotlib/mpl-data
running build_ext
running install_lib
copying build/lib.linux-i686-2.5/matplotlib/mpl-data/matplotlibrc -> /usr/local/lib/python2.5/site-packages/matplotlib/mpl-data
copying build/lib.linux-i686-2.5/matplotlib/mpl-data/matplotlib.conf -> /usr/local/lib/python2.5/site-packages/matplotlib/mpl-data
running install_egg_info
Removing /usr/local/lib/python2.5/site-packages/matplotlib-1.0.0-py2.5.egg-info
Writing /usr/local/lib/python2.5/site-packages/matplotlib-1.0.0-py2.5.egg-info

您应该检查您的 LD_LIBRARY_PATH 环境变量并检查您的 libpng 是否在其中。

python报的问题是动态加载的问题:用matplotlib重新编译没什么看的。

所以 :

  1. 使用以下命令找到 libpng.14.so 的位置:

    $> 找到 libpng.14.so

    请注意,该文件必须具有确切的名称,因此您可能必须创建一个符号链接,例如,如果您有 libpng.14.so.0 或类似的东西(通常在安装 lib 时会自动创建符号链接

    如果您没有任何 libpng.14.so.something 或 libpng.14.so,您可能需要重新安装 libpng 1.4(使用您的包管理器或直接从源代码)

  2. 检查 $LD_LIBRARY_PATH。 如果需要,请更改它:

    $> 导出 LD_LIBRARY_PATH=anewDir:$LD_LIBRARY_PATH

我对来自 macports 的 py27-matplotlib 有类似的问题。 在尝试了很多事情之后,我注意到我的站点包中有一个来自 matplotlib 1.10 的旧版本 _png.so。 so 链接到 libpng14 而不是我安装的较新版本。

删除旧的(未使用的!)_png.so,运行port uninstall/clean py27-matplotlib和一个全新的构建后,正确的 libpng 被链接并且 ipython/pylab 再次工作。

安装 libpng。 我认为 14 指的是 。

编辑

我会再次从源代码重建 matplotlib。 当你运行时:

python setup.py build

密切注意输出的开始并确保它找到它需要的库。 例如在我的盒子上:

basedirlist is: ['/usr/local', '/usr']
============================================================================
BUILDING MATPLOTLIB
            matplotlib: 1.0.0
                python: 2.5.4 (r254:67916, Oct 21 2009, 11:00:55)  [GCC
                        4.3.2]
              platform: linux2

REQUIRED DEPENDENCIES
                 numpy: 1.3.0
             freetype2: 9.20.3

OPTIONAL BACKEND DEPENDENCIES
                libpng: 1.2.36  ## what does yours say?
               Tkinter: Tkinter: 67737, Tk: 8.4, Tcl: 8.4
              wxPython: 2.8.10.1
                        * WxAgg extension not required for wxPython >= 2.8
                  Gtk+: gtk+: 2.16.1, glib: 2.22.4, pygtk: 2.14.1,
                        pygobject: 2.20.0
       Mac OS X native: no
                    Qt: no
                   Qt4: Qt: 4.5.1, PyQt4: 4.5.4
                 Cairo: 1.8.2

OPTIONAL DATE/TIMEZONE DEPENDENCIES
              datetime: present, version unknown
              dateutil: matplotlib will provide
                  pytz: 2009r

OPTIONAL USETEX DEPENDENCIES
                dvipng: no
           ghostscript: 8.64
                 latex: no
               pdftops: 0.10.7