Python 3.6 can find cairo libs but not Python 2.7

D'Arcy Cain darcy at
Fri Jul 13 06:18:29 EDT 2018

On 2018-07-12 04:17 PM, Terry Reedy wrote:
> On 7/12/2018 3:52 PM, D'Arcy Cain wrote:
>> $ python2.7 -c "import ctypes.util;
>> print(ctypes.util.find_library('cairo'))"
>> $ python3.6 -c "import ctypes.util;
>> print(ctypes.util.find_library('cairo'))"
>> None
>> I have the 3.6 version of py-cairo installed.  Any thoughts?
>> NetBSD 7.1.2
> what is sys.path?  Where in py-cairo installed?

For 3.6 it includes '/usr/pkg/lib/python3.6/site-packages' and for 2.7
it includes '/usr/pkg/lib/python2.7/site-packages'.  The py-cairo files
are in the 3.6 site-packages.  There are no Cairo files in the 2.7
Python directory.

I'm not sure why that matters though.  It's the system libraries that it
can't find unless having py-cairo installed is somehow blocking the
search for the libraries.

Of course, my actual use depends on a cairo package.  In fact, the
failure that led me to the above issue happens when I load cairocffi.

$ python3.6 -c "import cairocffi"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/pkg/lib/python3.6/site-packages/cairocffi/",
line 41, in <module>
    cairo = dlopen(ffi, 'cairo', 'cairo-2')
  File "/usr/pkg/lib/python3.6/site-packages/cairocffi/",
line 38, in dlopen
    raise OSError("dlopen() failed to load a library: %s" % ' /
OSError: dlopen() failed to load a library: cairo / cairo-2

D'Arcy J.M. Cain
Vybe Networks Inc.
IM:darcy at Vex.Net VoIP: sip:darcy at

More information about the Python-list mailing list