Amelio Vazquez-Reina
Amelio Vazquez-Reina

Reputation: 96264

Unable to import matplotlib._png (pylab)

I am unable to import matplotlib._png:

import matplotlib._png as _png ImportError: /home/james/opt/python/virtualenvs/work/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/_png.so: undefined symbol: png_set_longjmp_fn

This error prevents me from running import pylab (sincce this ultimately imports matplotlib._png).

I installed matplotlib from source, and made sure to add the path with local installations (/home/james/local) to basedir in setupext.py before running python setup.py install.

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [version 1.7.1]
              dateutil: yes [using dateutil version 2.1]
               tornado: yes [using tornado version 3.0.1]
             pyparsing: yes [using pyparsing version 1.5.7]
                 pycxx: yes [Couldn't import.  Using local copy.]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found Using local copy.]
              freetype: yes [version 16.0.10]
                   png: yes [version 1.2.10]

My research so far:

As can be seen above, matplotlib seems to find version 1.2.10 even though the version that I have under /home/james/local is 1.6.2:

$ find . -iname '*libpng*'                                                                                                  
./libpng16.so.16.1.0
./libpng16.so
./libpng16.so.16
./libpng16.a
./libpng.a
./libpng.so
./libpng16.la
./pkgconfig/libpng.pc
./pkgconfig/libpng16.pc
./libpng.la

More specifically, I modified the following line in setupext.py with:

return basedir_map.get(sys.platform, ['/home/james/local', '/usr/local', '/usr'])

but matplotlib seems to have found the system version:

$ locate libpng
/usr/lib/libpng.so
/usr/lib/libpng.so.3
/usr/lib/libpng.so.3.10.0
/usr/lib/libpng12.a
/usr/lib/libpng12.so
/usr/lib/libpng12.so.0
/usr/lib/libpng12.so.0.10.0

Could this be the problem? Why am I unable to import matplotlib._png?

Update:

Looking at setupext.py, it looks like python setup install queries pkg-config through the SetupPackage method _check_for_pkg_config to determine the version of libpng I have installed. It turns out that pkg-config is returning the system installation:

$ pkg-config --libs libpng
-lpng12

even though I have updated basedir in matplotlib's setupext.py, and LD_LIBRARY_PATH to make them point to the the more recent version of libpng that I have locally installed.

Any ideas on how to have pkg-config return the right version?

Upvotes: 2

Views: 3858

Answers (2)

user707650
user707650

Reputation:

It's a pkg-config issue; matplotlib's installation is (unfortunately, or perhaps not) relying too much on pkg-config's output.

Assuming you have build libpng the normal way, there should be a pkgconfig subdirectory in your /home/james/local/lib, which contains libpng.pc (and libpng16.pc). When setupext.py runs pkg-config, the latter should of course try and pick up the correct .pc file for libpng. For that, use the PKG_CONFIG_PATH variable and point it to the pkgconfig subdirectory:

$ export PKG_CONFIG_PATH=/home/james/local/lib/pkgconfig

Then, install matplotlib again, and see that it now finds the correct libpng version:

$ python setup.py build
basedirlist is: ['/usr/local', '/usr']
============================================================================
BUILDING MATPLOTLIB
            matplotlib: 1.1.0
                python: 2.7.4 (default, Apr  8 2013, 16:36:47)  [GCC 4.4.5]
              platform: linux2

REQUIRED DEPENDENCIES
                 numpy: 1.7.0
             freetype2: 12.0.6

OPTIONAL BACKEND DEPENDENCIES
                libpng: 1.6.1
               Tkinter: Tkinter: 81008, Tk: 8.4, Tcl: 8.4

(For me, with a different PKG_CONFIG_PATH of course. Yes, I may want to upgrade some dependencies.)

Note that I didn't even alter basedirlist; it's just at its default. In case pkg-config fails to now pick up some other package, just add more directories to PKG_CONFIG_PATH with colons in between. But I guess this should be enough.

Upvotes: 5

dsign
dsign

Reputation: 12700

Try

 export LD_LIBRARY_PATH=/home/james/local/lib

and then execute Matplotlib... that would point matplotlib to your local version.

Upvotes: 0

Related Questions