简体   繁体   English

matplotlib.pyplot问题python

[英]matplotlib.pyplot issue python

I'm experiencing a problem with matplotlib, to be more precise with pyplot. 我遇到了matplotlib的问题,更准确地说是pyplot。

Just after installing, doing 刚刚安装完毕,就做了

import matplotlib.pyplot

gives me this error: 给我这个错误:

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

So I have no idea what is going on. 所以我不知道发生了什么。 I'm on Mac OS X 10.6, I have installed python2.7 from disk image and matplotlib from the terminal by using the tar.gz and doing the usual 我在Mac OS X 10.6上,我已经使用tar.gz从终端安装了来自磁盘映像的python2.7和来自终端的matplotlib

python setup.py build
python setup.py install

When the installation starts I see: 安装开始时,我看到:

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

Any help guys please! 任何帮助的人请!

Cheers 干杯

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

I've been fighting this same problem and the answer was to install the ScipySuperpack. 我一直在解决同样的问题,答案是安装ScipySuperpack。 The problem (at least for me) was that I have a 64 bit version of Python, and the version of matplotlib I was pulling from github was 32 bit. 问题(至少对我来说)是我有一个64位版本的Python,我从github拉出来的matplotlib版本是32位。 I cloned the ScipySuperpack repository and ran the setup script and it worked. 我克隆了ScipySuperpack存储库并运行了安装脚本,它运行良好。

No amount of fighting with brew or ports was getting me anywhere. 没有任何与酿造或港口的战斗让我随处可见。

In case anyone has the same problem as me and finds this thread, here is how I solved it. 如果有人和我有同样的问题并找到这个帖子,这就是我解决它的方法。

First, I follow the current matplotlib README.osx, along with this guy's advice (not sure if that's necessary)... 首先,我遵循当前的matplotlib README.osx,以及这个人的建议 (不确定是否有必要)......

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"

I also set those variables as recommended by brew. 我还根据brew的建议设置了这些变量。

Then, I did the following (running from matplotlib build directory, after having built and installed) 然后,我做了以下(从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)

No libpng! 没有libpng! A bad sign... let's see the build output again... 一个糟糕的迹象......让我们再次看到构建输出......

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)

It's not using the right libpng: what does brew provide? 它没有使用正确的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

Let's try to fix that by copy-pasting the command but changing -lpng14 to -lpng15... (there's probably a better way to stop it from using the wrong one, but this worked) 让我们尝试通过复制粘贴命令来修复它,但是将-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)

I just wanted to add a few suggestions for people who might still be having trouble. 我只想为可能仍然遇到麻烦的人添加一些建议。 I've been searching around for a while and trying lots of different things. 我一直在寻找一段时间并尝试很多不同的东西。 Ultimately, it was one of the following that allowed me to import matplotlib.pyplot on Python 2.7.6 on OSX 10.6 (with X11 and XQuartz installed previously, perhaps outdated): 最终,它是下面的一个允许我在OSX 10.6上导入Python 2.7.6上的matplotlib.pyplot(先前安装了X11和XQuartz,可能已经过时):

  1. Installing pkg-info 安装pkg-info

     brew install pkg-info 
  2. Installing libpng from source to /usr/local/lib (configure --libdir=/usr/local) 从源代码安装libpng到/ usr / local / lib(configure --libdir = / usr / local)

  3. Installing XQuartz for Mac 安装XQuartz for Mac

  4. Deleting matplotlib folders from site-packages (probably old, failed attempts). 从站点包中删除matplotlib文件夹(可能是旧的,失败的尝试)。

  5. Running 运行

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

Finally, 最后,

port install py27-matplotlib

installed it, and I was able to import. 安装它,我能够导入。 The original error I had was 我遇到的原始错误是

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

Though some attempts ran into this error: 虽然有些尝试遇到了这个错误:

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>

I'm sorry I can't be more specific. 对不起,我不能更具体。

You should follow these directions for installing Matplotlib from source on OSX: https://github.com/matplotlib/matplotlib/blob/master/README.osx 您应按照以下说明在OSX上从源代码安装Matplotlib: https//github.com/matplotlib/matplotlib/blob/master/README.osx

OSX is a bit messy with the lib files, but following the directions from the link should resolve any issues you're having as it automatically installs the dependencies in a self-contained manner. OSX对lib文件有点混乱,但遵循链接中的指示应解决您遇到的任何问题,因为它会以自包含的方式自动安装依赖项。

I had same problem as OP. 我和OP有同样的问题。 I git cloned the repo and "python setup install" instead of pre-compiled version. 我git克隆了repo和“python setup install”而不是预编译版本。 Took about 20 minutes to compile and seems to work now. 花了大约20分钟编译,现在似乎工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM