Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting OSError: no library called "cairo-2" was found #2410

Open
capndave opened this issue Mar 18, 2025 · 1 comment
Open

Getting OSError: no library called "cairo-2" was found #2410

capndave opened this issue Mar 18, 2025 · 1 comment

Comments

@capndave
Copy link

capndave commented Mar 18, 2025

I've seen a number of other posts related to weezyprint or other libraries and problems with cairo, but none of them solved our issue. Some info:

  • On Mac M3, ARM64 and Sonoma 14.6 OS
  • Python 3.7 and we can't upgrade due to organizational hurdles
  • Weasyprint 51, we can't upgrade this much because of the above
  • We use mise for python version mgmt but are running our project from a .venv folder that is not in the .mise file path
  • We installed cairo with port install cairo (macports)
  • Since cairo is now in /opt/local/lib, we tried the following (and various combos of it):
export DYLD_LIBRARY_PATH=“/opt/local/lib:$DYLD_LIBRARY_PATH”
export PKG_CONFIG_PATH=“/opt/local/lib/pkgconfig:$PKG_CONFIG_PATH”
export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib
export PATH="/opt/local/lib:$PATH"

Here's what we see:

Traceback (most recent call last):
  File "wsgiDev.py", line 2, in <module>
    from api.main import app
  File "/Users/davidthompson/Code/hsauditService/api/main.py", line 9, in <module>
    from api.resources.letter.letter import (
  File "/Users/davidthompson/Code/hsauditService/api/resources/letter/letter.py", line 14, in <module>
    from api.celeryTasks.app_tasks import massGenerateLetters
  File "/Users/davidthompson/Code/hsauditService/api/celeryTasks/app_tasks.py", line 16, in <module>
    from api.resources.letter.letterHelpers import createPDFFileFromHTML, renderWrapper
  File "/Users/davidthompson/Code/hsauditService/api/resources/letter/letterHelpers.py", line 9, in <module>
    from weasyprint import HTML
  File "/Users/davidthompson/.virtualenvs/hsauditservice/lib/python3.7/site-packages/weasyprint/__init__.py", line 440, in <module>
    from .css import preprocess_stylesheet  # noqa isort:skip
  File "/Users/davidthompson/.virtualenvs/hsauditservice/lib/python3.7/site-packages/weasyprint/css/__init__.py", line 30, in <module>
    from . import computed_values, media_queries
  File "/Users/davidthompson/.virtualenvs/hsauditservice/lib/python3.7/site-packages/weasyprint/css/computed_values.py", line 18, in <module>
    from .. import text
  File "/Users/davidthompson/.virtualenvs/hsauditservice/lib/python3.7/site-packages/weasyprint/text.py", line 14, in <module>
    import cairocffi as cairo
  File "/Users/davidthompson/.virtualenvs/hsauditservice/lib/python3.7/site-packages/cairocffi/__init__.py", line 49, in <module>
    ('libcairo.so.2', 'libcairo.2.dylib', 'libcairo-2.dll'))
  File "/Users/davidthompson/.virtualenvs/hsauditservice/lib/python3.7/site-packages/cairocffi/__init__.py", line 44, 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': dlopen(libcairo.so.2, 0x0002): tried: 'libcairo.so.2' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibcairo.so.2' (no such file), '/Users/davidthompson/.local/share/mise/installs/python/3.7.17/lib/libcairo.so.2' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/davidthompson/.local/share/mise/installs/python/3.7.17/lib/libcairo.so.2' (no such file), '/usr/lib/libcairo.so.2' (no such file, not in dyld cache), 'libcairo.so.2' (no such file), '/usr/local/lib/libcairo.so.2' (no such file), '/usr/lib/libcairo.so.2' (no such file, not in dyld cache).  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.so.2'
cannot load library 'libcairo.2.dylib': dlopen(libcairo.2.dylib, 0x0002): tried: 'libcairo.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibcairo.2.dylib' (no such file), '/Users/davidthompson/.local/share/mise/installs/python/3.7.17/lib/libcairo.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/davidthompson/.local/share/mise/installs/python/3.7.17/lib/libcairo.2.dylib' (no such file), '/usr/lib/libcairo.2.dylib' (no such file, not in dyld cache), 'libcairo.2.dylib' (no such file), '/usr/local/lib/libcairo.2.dylib' (no such file), '/usr/lib/libcairo.2.dylib' (no such file, not in dyld cache).  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.2.dylib'
cannot load library 'libcairo-2.dll': dlopen(libcairo-2.dll, 0x0002): tried: 'libcairo-2.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibcairo-2.dll' (no such file), '/Users/davidthompson/.local/share/mise/installs/python/3.7.17/lib/libcairo-2.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/davidthompson/.local/share/mise/installs/python/3.7.17/lib/libcairo-2.dll' (no such file), '/usr/lib/libcairo-2.dll' (no such file, not in dyld cache), 'libcairo-2.dll' (no such file), '/usr/local/lib/libcairo-2.dll' (no such file), '/usr/lib/libcairo-2.dll' (no such file, not in dyld cache).  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo-2.dll'
@liZe
Copy link
Member

liZe commented Mar 18, 2025

Hi!

To be honest, Python 3.7 is deprecated by since June 2023, Cairo use is dropped in WeasyPrint since April 2021, version 51 has been released in 2019, I’ve never heard of Mise, and Macport has never been the official way to install dependencies for macOS in our documentation. I’m not sure we’ll be able to help you.

/opt/local/lib has never been tried to find libcairo.2.dylib according to your error messages, so I suppose that you didn’t set the environment variable in the same shell as the one used to launch your application. We currently use DYLD_FALLBACK_LIBRARY_PATH for the CI.

In a terminal, you can try:

DYLD_FALLBACK_LIBRARY_PATH="/opt/local/lib" /Users/davidthompson/.virtualenvs/hsauditservice/bin/python -m weasyprint --info

If /opt/local/lib/libcairo.2.dylib really exists, it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants