pythoncmd

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


How to fix this error?

C:\Users\vanvl\OneDrive\Bureaublad\Progammeren\Project 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:\Users\vanvl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\Custom_Widgets\ProjectMaker.py", line 14, in <module>
    import cairosvg
  File "C:\Users\vanvl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\cairosvg\__init__.py", line 26, in <module>
    from . import surface  # noqa isort:skip
  File "C:\Users\vanvl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\cairosvg\surface.py", line 9, in <module>
    import cairocffi as cairo
  File "C:\Users\vanvl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\cairocffi\__init__.py", line 48, in <module>
    cairo = dlopen(
  File "C:\Users\vanvl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\cairocffi\__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

Solution

  • This is quite an annoying dependency problem because cairocffi is not built for windows, you need the additional dependency as explained there: https://doc.courtbouillon.org/cairocffi/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