4

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
MattDMo
  • 100,794
  • 21
  • 241
  • 231
Ic3Fox
  • 85
  • 1
  • 1
  • 8

2 Answers2

12

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

Oily
  • 538
  • 3
  • 11
  • I started working with something els but i will check to use this on my Pyqt5. Ty – Ic3Fox Jan 03 '23 at 19:22
  • It still to confusing i started using WPF for C# to design. But thx for answering – Ic3Fox Jan 03 '23 at 19:39
  • 3
    Any idea how to resolve same issue on macOS ? – Gustav Rasmussen May 15 '23 at 21:47
  • On my M1 Mac running Ventura the problem was that brew had installed libs where my cairo in $HOME could not see. The workaround was to set DYLD_FALLBACK_LIBRARY_PATH as an environment variable. I found this explained here https://github.com/squidfunk/mkdocs-material/issues/5121 – snow6oy Jul 02 '23 at 22:00
0

On ubuntu:

sudo apt install libcairo2
tread
  • 10,133
  • 17
  • 95
  • 170