OSError: no library called "cairo-2" was found (from Custom_Widgets import ProjectMaker)

Question:

How to fix this error?

C:UsersvanvlOneDriveBureaubladProgammerenProject 1.02.2>python
Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from Custom_Widgets import ProjectMaker
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:UsersvanvlAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagesCustom_WidgetsProjectMaker.py", line 14, in <module>
    import cairosvg
  File "C:UsersvanvlAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagescairosvg__init__.py", line 26, in <module>
    from . import surface  # noqa isort:skip
  File "C:UsersvanvlAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagescairosvgsurface.py", line 9, in <module>
    import cairocffi as cairo
  File "C:UsersvanvlAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagescairocffi__init__.py", line 48, in <module>
    cairo = dlopen(
  File "C:UsersvanvlAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagescairocffi__init__.py", line 45, in dlopen
    raise OSError(error_message)  # pragma: no cover
OSError: no library called "cairo-2" was found
no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x7e
cannot load library 'libcairo-2.dll': error 0x7e
Asked By: Ic3Fox

||

Answers:

This is quite an annoying dependency problem because cairocffi is not built for windows, you need the additional dependency as explained there: https://cairocffi.readthedocs.io/en/stable/overview.html#installing-cairo-on-windows

A quicker solution is to do the following:
I used pipwin which install from an unofficial repository https://www.lfd.uci.edu/~gohlke/pythonlibs/#pycairo

pip install pipwin

pipwin install cairocffi

Also see this related issue: get cairosvg working in windows

Answered By: Oily
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.