rem rem - 2 years ago 266
Python Question

Python not finding library in /usr/lib/x86_64-linux-gnu that ldconfig -p does find

I'm trying to use the python module cairocffi. I use Debian (Stretch) on x86-64, so I installed the apt package

and installed the
python package using pip. This all went well. But when I try to import it, it fails to load the module:

$ python -c "import cairocffi; print('OK')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/cairocffi/", line 46, in <module>
cairo = dlopen(ffi, 'cairo', 'cairo-2')
File "/usr/local/lib/python2.7/dist-packages/cairocffi/", line 43, in dlopen
raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2

does know about

$ sudo ldconfig -p | grep cairo (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/ (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/ (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/ (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/ (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/ (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/ (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/ (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/

and when I run python with a modified
, it works:

$ LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu python -c "import cairocffi; print('OK')"

I don't want to have to run python on a modified
to run this script for the sake of scalability and maintainability, but I can't figure out why it isn't picking up the library that apparently the dynamic linker does know about. What am I missing?

rem rem
Answer Source

It turns out there was an old hiding in my /usr/lib (which is a dependency of libcairo), and a newer libpixman in the folder where libcairo was installed. So when LD_LIBRARY_PATH was set to the location of libcairo it would pick up the new libpixman which worked, and when it was not set it would pick up the old one. Removing the old libpixman from /usr/lib fixed everything.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download