pythonwindowscairo

Python: OSError: cannot load library libcairo.so.2


I'm having some trouble running a python script on my Windows 7 platform. I've installed Python and also cairo, last one using "pip". I'm running the script using this command:

C:\Python34>python.exe label/make_label.py

and I get the following error message:

Traceback (most recent call last):
  File "label/make_label.py", line 6, in <module>
    import cairocffi as cairo
  File "C:\Python34\lib\site-packages\cairocffi\__init__.py", line 41, in <modul
e>
    cairo = dlopen(ffi, *CAIRO_NAMES)
  File "C:\Python34\lib\site-packages\cairocffi\__init__.py", line 34, in dlopen

    return ffi.dlopen(names[0])  # pragma: no cover
  File "C:\Python34\lib\site-packages\cffi\api.py", line 118, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "C:\Python34\lib\site-packages\cffi\api.py", line 411, in _make_ffi_libra
ry
    backendlib = _load_backend_lib(backend, libname, flags)
  File "C:\Python34\lib\site-packages\cffi\api.py", line 400, in _load_backend_l
ib
    return backend.load_library(name, flags)
OSError: cannot load library libcairo.so.2: error 0x7e

What I've already done is the following:

I don't know what other information could be useful in solving this but please let me know and I'll try to add it.


Solution

  • It seems cairo depends a shared library which is not in standard search library, however, the python is calling dlopen to dynamic load the library, so you could try to put the libcairo.so.2(if it's a link, then make sure the reference locates at the same folder) in the working directory. You can also try pkg-config to set the environment. see here http://people.freedesktop.org/~dbn/pkg-config-guide.html