Problem with matplotlib.pyplot python

I have a problem with matplotlib, more precisely with pyplot.

Immediately after installation by making

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 

Therefore, I have no idea what is happening. I am on Mac OS X 10.6, I installed python2.7 from a disk image and matplotlib from a terminal using tar.gz and performed the usual

 python setup.py build python setup.py install 

When starting the installation, 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 will like it!

Greetings

+4
source share
5 answers

http://fonnesbeck.imtqy.com/ScipySuperpack/

I struggled with the same problem and the answer was to install ScipySuperpack. The problem (at least for me) was that I had a 64-bit version of Python, and the version of matplotlib that I pulled from github was 32-bit. I cloned the ScipySuperpack repository and ran the installation script, and it worked.

No fighting with brew or ports took me anywhere.

+4
source

If someone has the same problem as mine and she finds this thread, that’s how I solved it.

Firstly, I am following the current matplotlib README.osx as well as this guy advice (not sure if this is 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 these variables as recommended by brew.

Then I did the following (executed from the matplotlib assembly directory after creating and installing it)

 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! Bad sign ... see the build result 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 does not use the correct libpng: what does brew offer?

 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 

Try fixing this by copying the command, but changing -lpng14 to -lpng15 ... (probably the best way to stop using the wrong one, but it 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) 
+2
source

I just wanted to add a few suggestions for people who may still be having problems. I searched around and tried many different things. Ultimately, this was one of the following, which allowed me to import matplotlib.pyplot in Python 2.7.6 on OSX 10.6 (with X11 and XQuartz already installed, possibly outdated):

  • Install pkg-info

     brew install pkg-info 
  • Install libpng from source to / usr / local / lib (configure --libdir = / usr / local)

  • Install XQuartz for Mac

  • Removing matplotlib folders from site packages (possibly old failed attempts).

  • Launch

     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 it. The initial error that 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 

Although some errors fell 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> 

Sorry, I could not be more specific.

+2
source

You must follow these instructions to install Matplotlib from source in OSX: https://github.com/matplotlib/matplotlib/blob/master/README.osx

OSX is a bit confused with lib files, but following the directions in this link should fix any problems you may have, as it automatically installs dependencies offline.

+1
source

I had the same problem as the OP. I git cloned the repo and the "install python installation" instead of the precompiled version. It took about 20 minutes to compile and seems to be working now.

0
source

Source: https://habr.com/ru/post/1382381/


All Articles