【问题标题】:matplotlib.pyplot issue pythonmatplotlib.pyplot 问题 python
【发布时间】:2011-11-21 21:40:13
【问题描述】:

我在使用 matplotlib 时遇到问题,更准确地说是使用 pyplot。

刚安装完,做

import matplotlib.pyplot

给我这个错误:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so, 2): Symbol not found: _png_create_info_struct
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so

所以我不知道发生了什么。我在 Mac OS X 10.6 上,我已经从磁盘映像安装了 python2.7,并使用 tar.gz 从终端安装了 matplotlib 并执行通常的操作

python setup.py build
python setup.py install

安装开始时我看到:

BUILDING MATPLOTLIB
            matplotlib: 1.1.0
                python: 2.7 (r27:82508, Jul  3 2010, 21:12:11)  [GCC 4.0.1
                        (Apple Inc. build 5493)]
              platform: darwin

REQUIRED DEPENDENCIES
                 numpy: 1.6.1
             freetype2: 10.0.4

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

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

OPTIONAL USETEX DEPENDENCIES
                dvipng: 1.13
           ghostscript: 8.61
                 latex: 3.1415926

请大家帮忙!

干杯

【问题讨论】:

  • 你有libpng(和可能的zlib)依赖吗?

标签: python installation matplotlib


【解决方案1】:

http://fonnesbeck.github.io/ScipySuperpack/

我一直在解决同样的问题,答案是安装 ScipySuperpack。问题(至少对我而言)是我有一个 64 位版本的 Python,而我从 github 提取的 matplotlib 版本是 32 位。我克隆了 ScipySuperpack 存储库并运行了安装脚本,它工作正常。

再多的与 brew 或 ports 的斗争都无法让我走到任何地方。

【讨论】:

  • >>> 导入 matplotlib.pyplot;加载需要 5 秒,但成功了!感谢分享。
  • 比一系列令人困惑的 shell 命令要好得多。 +1 +1 +1
【解决方案2】:

如果有人和我有同样的问题并找到这个帖子,我就是这样解决的。

首先,我遵循当前的 matplotlib README.osx 以及 this guy's advice(不确定是否有必要)...

brew install freetype --universal
brew install libpng --universal
export CPPFLAGS="-I/usr/local/opt/libpng/include -I/usr/local/opt/freetype/include"
export LDFLAGS=" -L/usr/local/opt/libpng/lib  -L/usr/local/opt/freetype/lib"

我还按照 brew 的建议设置了这些变量。

然后,我做了以下 (在构建和安装后从 matplotlib 构建目录运行)

drigz@mbp matplotlib 0$ find . -name _png.so
./build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so
drigz@mbp matplotlib 0$ otool -L ./build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so
./build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so:
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 830.0.0)

没有libpng!一个不好的迹象...让我们再次查看构建输出...

drigz@mbp matplotlib 0$ rm ./build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so
drigz@mbp matplotlib 0$ python setup.py build
[SNIP]
c++ -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -isysroot /Developer/SDKs/MacOSX10.6.sdk -g -L/usr/local/opt/libpng/lib -L/usr/local/opt/freetype/lib -I/usr/local/opt/libpng/include -I/usr/local/opt/freetype/include build/temp.macosx-10.6-intel-2.7/src/_png.o build/temp.macosx-10.6-intel-2.7/src/mplutils.o build/temp.macosx-10.6-intel-2.7/CXX/cxx_extensions.o build/temp.macosx-10.6-intel-2.7/CXX/cxxsupport.o build/temp.macosx-10.6-intel-2.7/CXX/IndirectPythonInterface.o build/temp.macosx-10.6-intel-2.7/CXX/cxxextensions.o -L/sw/lib -L/usr/local/lib -L/usr/lib -L/usr/X11/lib -lpng14 -lz -lstdc++ -lm -o build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so
ld: warning: in /sw/lib/libpng14.dylib, file was built for i386 which is not the architecture being linked (x86_64)

它没有使用正确的 libpng:brew 提供了什么?

drigz@mbp matplotlib 0$ echo $LDFLAGS
 -L/usr/local/opt/libpng/lib  -L/usr/local/opt/freetype/lib
drigz@mbp matplotlib 0$ ls /usr/local/opt/libpng/lib 
libpng.a          libpng.la         libpng15.a        pkgconfig
libpng.dylib      libpng15.15.dylib libpng15.dylib

让我们尝试通过复制粘贴命令来解决这个问题,但将 -lpng14 更改为 -lpng15...(可能有更好的方法来阻止它使用错误的命令,但这很有效)

drigz@mbp matplotlib 0$ c++ -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -isysroot /Developer/SDKs/MacOSX10.6.sdk -g -L/usr/local/opt/libpng/lib -L/usr/local/opt/freetype/lib -I/usr/local/opt/libpng/include -I/usr/local/opt/freetype/include build/temp.macosx-10.6-intel-2.7/src/_png.o build/temp.macosx-10.6-intel-2.7/src/mplutils.o build/temp.macosx-10.6-intel-2.7/CXX/cxx_extensions.o build/temp.macosx-10.6-intel-2.7/CXX/cxxsupport.o build/temp.macosx-10.6-intel-2.7/CXX/IndirectPythonInterface.o build/temp.macosx-10.6-intel-2.7/CXX/cxxextensions.o -L/sw/lib -L/usr/local/lib -L/usr/lib -L/usr/X11/lib -lpng15 -lz -lstdc++ -lm -o build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so
drigz@mbp matplotlib 0$ python setup.py install
[SNIP]
drigz@mbp matplotlib 0$ otool -L /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so:
        /usr/local/opt/libpng/lib/libpng15.15.dylib (compatibility version 29.0.0, current version 29.0.0)
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 830.0.0)

【讨论】:

  • 谢谢。它引导我朝着正确的方向前进。我使用以下导出来编译。请注意对 freetype2 的引用。 CPPFLAGS="-I/usr/local/opt/libpng/include -I/usr/local/opt/freetype/include -I/usr/local/opt/freetype/include/freetype2"
【解决方案3】:

我只是想为可能仍有问题的人添加一些建议。我已经四处寻找并尝试了很多不同的东西。最终,是以下其中一项允许我在 OSX 10.6 上的 Python 2.7.6 上导入 matplotlib.pyplot(之前安装了 X11 和 XQuartz,可能已经过时):

  1. 安装 pkg-info

    brew install pkg-info
    
  2. 将 libpng 从源安装到 /usr/local/lib(配置 --libdir=/usr/local)

  3. 为 Mac 安装 XQuartz

  4. 从站点包中删除 matplotlib 文件夹(可能是旧的,失败的尝试)。

  5. 跑步

    ln -s /usr/local/opt/freetype/include/freetype2 /usr/local/include/freetype
    

最后,

port install py27-matplotlib

安装它,我可以导入。我原来的错误是

ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/_png.so, 2): Library not loaded: /opt/local/lib/libpng15.15.dylib
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/_png.so Reason: image not found

虽然有些尝试遇到了这个错误:

In file included from src/ft2font.cpp:3:
In file included from src/ft2font.h:16:
/usr/X11/include/ft2build.h:56:10: fatal error: 'freetype/config/ftheader.h' file not found
#include <freetype/config/ftheader.h>

很抱歉,我不能更具体。

【讨论】:

    【解决方案4】:

    您应该按照以下说明在 OSX 上从源代码安装 Matplotlib:https://github.com/matplotlib/matplotlib/blob/master/README.osx

    OSX 的 lib 文件有点混乱,但是按照链接中的说明应该可以解决您遇到的任何问题,因为它会以独立的方式自动安装依赖项。

    【讨论】:

      【解决方案5】:

      我遇到了和 OP 一样的问题。我 git 克隆了 repo 和“python setup install”而不是预编译版本。编译花了大约 20 分钟,现在似乎可以工作了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-30
        • 1970-01-01
        • 2015-07-30
        • 2014-10-09
        • 1970-01-01
        • 1970-01-01
        • 2022-01-14
        • 1970-01-01
        相关资源
        最近更新 更多