Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib.pyplot issue python

I'm experiencing a problem with matplotlib, to be more precise with 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

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

like image 396
eikonal Avatar asked Jan 18 '23 05:01

eikonal


2 Answers

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

I've been fighting this same problem and the answer was to install the 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. I cloned the ScipySuperpack repository and ran the setup script and it worked.

No amount of fighting with brew or ports was getting me anywhere.

like image 98
Ben Avatar answered Jan 28 '23 14:01

Ben


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)...

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.

Then, I did the following (running from matplotlib build directory, after having built and installed)

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! 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?

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)

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)
like image 23
Rodrigo Queiro Avatar answered Jan 28 '23 15:01

Rodrigo Queiro