rem rem - 7 months ago 88
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

libcairo2-dev
and installed the
cairocffi
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/__init__.py", line 46, in <module>
cairo = dlopen(ffi, 'cairo', 'cairo-2')
File "/usr/local/lib/python2.7/dist-packages/cairocffi/__init__.py", 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


However,
ldconfig
does know about
libcairo.so
:

$ sudo ldconfig -p | grep cairo
libpangocairo-1.0.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0
libpangocairo-1.0.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so
libcairo.so.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcairo.so.2
libcairo.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcairo.so
libcairo-script-interpreter.so.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcairo-script-interpreter.so.2
libcairo-script-interpreter.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcairo-script-interpreter.so
libcairo-gobject.so.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcairo-gobject.so.2
libcairo-gobject.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcairo-gobject.so


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

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


I don't want to have to run python on a modified
LD_LIBRARY_PATH
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

It turns out there was an old libpixman.so 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.