Skip to content

Cairocffi can't find cairo library #5121

Closed

Description

@bigmike36c

Context

I'm running mkdocs locally on my M1 mac and using poetry to manage my virtual environment. The same issue occurs if you use pip.

Bug description

To use the social plugin, mkdocs requires installing pillow and cairosvg. Additionally, Cairo Graphics and its dependencies must be installed as stated in the docs. I'm using an M1 mac so I used the following command:

brew install cairo freetype libffi libjpeg libpng zlib

These libraries installed without issue. However, upon running mkdocs serve I receive the following error:

OSError: no library called "cairo-2" was found
no library called "cairo" was found
no library called "libcairo-2" was found

It appears to be looking for these libraries inside of the python installation instead of inside the homebrew folder. My current workaround is to use the following environment variable as mentioned in this issue:

export DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib

Related links

Reproduction

example.zip

Steps to reproduce

  1. Create a virtual environment
  2. Run pip install -r requirements.lock.txt
  3. Run mkdocs serve or mkdocs build

Browser

Other

Before submitting

Activity

  1. added
    needs investigation
    on Feb 28, 2023
  2. squidfunk commented on Feb 28, 2023

    @squidfunk
    Owner

    Thanks for reporting. I finally also got a brand new M2, and funnily, I had no problems with Cairo. I downloaded and ran your example with the steps you outlined, everything builds successfully. Here's the output:

    squidfunk@squidfunk Downloads/example $ python -m venv venv    
    squidfunk@squidfunk Downloads/example $ . ./venv/bin/activate
    (venv) squidfunk@squidfunk Downloads/example $ pip install -r requirements.lock.txt
    Collecting CairoSVG==2.6.0
      Using cached CairoSVG-2.6.0-py3-none-any.whl (43 kB)
    Collecting Jinja2==3.1.2
      Using cached Jinja2-3.1.2-py3-none-any.whl (133 kB)
    Collecting Markdown==3.3.7
      Using cached Markdown-3.3.7-py3-none-any.whl (97 kB)
    Collecting MarkupSafe==2.1.2
      Using cached MarkupSafe-2.1.2-cp311-cp311-macosx_10_9_universal2.whl (17 kB)
    Collecting Pillow==9.4.0
      Using cached Pillow-9.4.0-cp311-cp311-macosx_11_0_arm64.whl (3.0 MB)
    Collecting PyYAML==6.0
      Using cached PyYAML-6.0-cp311-cp311-macosx_11_0_arm64.whl (167 kB)
    Collecting Pygments==2.14.0
      Using cached Pygments-2.14.0-py3-none-any.whl (1.1 MB)
    Collecting cairocffi==1.4.0
      Using cached cairocffi-1.4.0.tar.gz (69 kB)
      Preparing metadata (setup.py) ... done
    Collecting certifi==2022.12.7
      Using cached certifi-2022.12.7-py3-none-any.whl (155 kB)
    Collecting cffi==1.15.1
      Using cached cffi-1.15.1-cp311-cp311-macosx_11_0_arm64.whl (174 kB)
    Collecting charset-normalizer==3.0.1
      Using cached charset_normalizer-3.0.1-cp311-cp311-macosx_11_0_arm64.whl (121 kB)
    Collecting click==8.1.3
      Using cached click-8.1.3-py3-none-any.whl (96 kB)
    Collecting colorama==0.4.6
      Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB)
    Collecting cssselect2==0.7.0
      Using cached cssselect2-0.7.0-py3-none-any.whl (15 kB)
    Collecting defusedxml==0.7.1
      Using cached defusedxml-0.7.1-py2.py3-none-any.whl (25 kB)
    Collecting ghp-import==2.1.0
      Using cached ghp_import-2.1.0-py3-none-any.whl (11 kB)
    Collecting idna==3.4
      Using cached idna-3.4-py3-none-any.whl (61 kB)
    Collecting importlib-metadata==6.0.0
      Downloading importlib_metadata-6.0.0-py3-none-any.whl (21 kB)
    Collecting mergedeep==1.3.4
      Using cached mergedeep-1.3.4-py3-none-any.whl (6.4 kB)
    Collecting mkdocs-material-extensions==1.1.1
      Using cached mkdocs_material_extensions-1.1.1-py3-none-any.whl (7.9 kB)
    Collecting mkdocs-material==9.0.15
      Downloading mkdocs_material-9.0.15-py3-none-any.whl (7.7 MB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.7/7.7 MB 2.3 MB/s eta 0:00:00
    Collecting mkdocs==1.4.2
      Using cached mkdocs-1.4.2-py3-none-any.whl (3.7 MB)
    Collecting packaging==23.0
      Using cached packaging-23.0-py3-none-any.whl (42 kB)
    Requirement already satisfied: pip==22.3.1 in ./venv/lib/python3.11/site-packages (from -r requirements.lock.txt (line 24)) (22.3.1)
    Collecting pycparser==2.21
      Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
    Collecting pymdown-extensions==9.9.2
      Using cached pymdown_extensions-9.9.2-py3-none-any.whl (219 kB)
    Collecting python-dateutil==2.8.2
      Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
    Collecting pyyaml-env-tag==0.1
      Using cached pyyaml_env_tag-0.1-py3-none-any.whl (3.9 kB)
    Collecting regex==2022.10.31
      Using cached regex-2022.10.31-cp311-cp311-macosx_11_0_arm64.whl (287 kB)
    Collecting requests==2.28.2
      Using cached requests-2.28.2-py3-none-any.whl (62 kB)
    Requirement already satisfied: setuptools==65.6.3 in ./venv/lib/python3.11/site-packages (from -r requirements.lock.txt (line 31)) (65.6.3)
    Collecting six==1.16.0
      Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
    Collecting tinycss2==1.2.1
      Using cached tinycss2-1.2.1-py3-none-any.whl (21 kB)
    Collecting urllib3==1.26.14
      Using cached urllib3-1.26.14-py2.py3-none-any.whl (140 kB)
    Collecting watchdog==2.3.0
      Using cached watchdog-2.3.0-cp311-cp311-macosx_11_0_arm64.whl (90 kB)
    Collecting webencodings==0.5.1
      Using cached webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
    Collecting wheel==0.38.4
      Downloading wheel-0.38.4-py3-none-any.whl (36 kB)
    Collecting zipp==3.15.0
      Downloading zipp-3.15.0-py3-none-any.whl (6.8 kB)
    Installing collected packages: webencodings, charset-normalizer, zipp, wheel, watchdog, urllib3, tinycss2, six, regex, PyYAML, Pygments, pycparser, Pillow, packaging, mkdocs-material-extensions, mergedeep, MarkupSafe, Markdown, idna, defusedxml, colorama, click, certifi, requests, pyyaml-env-tag, python-dateutil, pymdown-extensions, Jinja2, importlib-metadata, cssselect2, cffi, ghp-import, cairocffi, mkdocs, CairoSVG, mkdocs-material
      DEPRECATION: cairocffi is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
      Running setup.py install for cairocffi ... done
    Successfully installed CairoSVG-2.6.0 Jinja2-3.1.2 Markdown-3.3.7 MarkupSafe-2.1.2 Pillow-9.4.0 PyYAML-6.0 Pygments-2.14.0 cairocffi-1.4.0 certifi-2022.12.7 cffi-1.15.1 charset-normalizer-3.0.1 click-8.1.3 colorama-0.4.6 cssselect2-0.7.0 defusedxml-0.7.1 ghp-import-2.1.0 idna-3.4 importlib-metadata-6.0.0 mergedeep-1.3.4 mkdocs-1.4.2 mkdocs-material-9.0.15 mkdocs-material-extensions-1.1.1 packaging-23.0 pycparser-2.21 pymdown-extensions-9.9.2 python-dateutil-2.8.2 pyyaml-env-tag-0.1 regex-2022.10.31 requests-2.28.2 six-1.16.0 tinycss2-1.2.1 urllib3-1.26.14 watchdog-2.3.0 webencodings-0.5.1 wheel-0.38.4 zipp-3.15.0
    
    [notice] A new release of pip available: 22.3.1 -> 23.0.1
    [notice] To update, run: pip install --upgrade pip
    
    (venv) squidfunk@squidfunk Downloads/example $ mkdocs build
    WARNING  -  The "social" plugin needs the "site_url" configuration option to be defined. It will likely not work correctly.
    INFO     -  Cleaning site directory
    INFO     -  Building documentation to directory: /Users/squidfunk/Downloads/example/site
    INFO     -  Documentation built in 0.59 seconds
    (venv) squidfunk@squidfunk Downloads/example $ find .cache 
    .cache
    .cache/plugin
    .cache/plugin/social
    .cache/plugin/social/Roboto-Medium.ttf
    .cache/plugin/social/Roboto-Light.ttf
    .cache/plugin/social/e8bfc1c7a8cace411c44cf75a4758b35.png # <- successfully generated
    .cache/plugin/social/Roboto-Regular.ttf
    .cache/plugin/social/Roboto-MediumItalic.ttf
    .cache/plugin/social/Roboto-ThinItalic.ttf
    .cache/plugin/social/Roboto-BoldItalic.ttf
    .cache/plugin/social/Roboto-LightItalic.ttf
    .cache/plugin/social/Roboto-Italic.ttf
    .cache/plugin/social/Roboto-BlackItalic.ttf
    .cache/plugin/social/Roboto-Bold.ttf
    .cache/plugin/social/Roboto-Thin.ttf
    .cache/plugin/social/Roboto-Black.ttf

    I just installed cairo with the method mentioned in the docs (using brew). All good. Thus, I cannot reproduce the problem. It also sounds more like a Python or OS-related issue, since you can make it work by specificing the path explicitly. I'd try to search for similar answers on StackOverflow. Closing, as it's nothing directly related to Material for MkDocs.

  3. added
    bug
    upstream
    and removed
    needs investigation
    on Feb 28, 2023
  4. bilal-fazlani commented on Jul 31, 2023

    @bilal-fazlani

    @bigmike36c did you ever find the cause of this? I am setting a new M1 Mac and running into same issue.

  5. bigmike36c commented on Jul 31, 2023

    @bigmike36c
    Author

    No, unfortunately I was never able to resolve this issue on my Mac.

  6. jeichenseerNRX commented on Sep 25, 2023

    @jeichenseerNRX

    @bigmike36c and @bilal-fazlani - After installing cairo with Homebrew, I had to manually copy the library to a location in my path:

    cp /opt/homebrew/Cellar/cairo/1.16.0_5/lib/libcairo.2.dylib /usr/local/lib

  7. squidfunk commented on Sep 26, 2023

    @squidfunk
    Owner

    @jeichenseerNRX I think you just need to run brew link cairo – that should create the symbolic links:

    brew link cairo -v
    Linking /opt/homebrew/Cellar/cairo/1.16.0_5... 
    ln -s ../Cellar/cairo/1.16.0_5/bin/cairo-sphinx cairo-sphinx
    ln -s ../Cellar/cairo/1.16.0_5/bin/cairo-trace cairo-trace
    ln -s ../Cellar/cairo/1.16.0_5/include/cairo cairo
    ln -s ../../../Cellar/cairo/1.16.0_5/share/gtk-doc/html/cairo cairo
    ln -s ../Cellar/cairo/1.16.0_5/lib/cairo cairo
    ln -s ../Cellar/cairo/1.16.0_5/lib/libcairo-gobject.2.dylib libcairo-gobject.2.dylib
    ln -s ../Cellar/cairo/1.16.0_5/lib/libcairo-gobject.a libcairo-gobject.a
    ln -s ../Cellar/cairo/1.16.0_5/lib/libcairo-gobject.dylib libcairo-gobject.dylib
    ln -s ../Cellar/cairo/1.16.0_5/lib/libcairo-script-interpreter.2.dylib libcairo-script-interpreter.2.dylib
    ln -s ../Cellar/cairo/1.16.0_5/lib/libcairo-script-interpreter.a libcairo-script-interpreter.a
    ln -s ../Cellar/cairo/1.16.0_5/lib/libcairo-script-interpreter.dylib libcairo-script-interpreter.dylib
    ln -s ../Cellar/cairo/1.16.0_5/lib/libcairo.2.dylib libcairo.2.dylib
    ln -s ../Cellar/cairo/1.16.0_5/lib/libcairo.a libcairo.a
    ln -s ../Cellar/cairo/1.16.0_5/lib/libcairo.dylib libcairo.dylib
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-fc.pc cairo-fc.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-ft.pc cairo-ft.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-gobject.pc cairo-gobject.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-pdf.pc cairo-pdf.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-png.pc cairo-png.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-ps.pc cairo-ps.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-quartz-font.pc cairo-quartz-font.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-quartz-image.pc cairo-quartz-image.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-quartz.pc cairo-quartz.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-script.pc cairo-script.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-svg.pc cairo-svg.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-tee.pc cairo-tee.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-xcb-shm.pc cairo-xcb-shm.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-xcb.pc cairo-xcb.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-xlib-xrender.pc cairo-xlib-xrender.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo-xlib.pc cairo-xlib.pc
    ln -s ../../Cellar/cairo/1.16.0_5/lib/pkgconfig/cairo.pc cairo.pc
    31 symlinks created.
    
  8. squidfunk commented on Sep 26, 2023

    @squidfunk
    Owner

    I wonder however, why Homebrew didn't do that when you installed it. Was there some kind of error message?

  9. electronick-co commented on Nov 27, 2023

    @electronick-co

    I had the same issue on windows, solved it with these lines:

    pip install pipwin
    pipwin install cairocffi

  10. slobentanzer commented on Feb 19, 2024

    @slobentanzer

    Can confirm the issue is still there on current Mac hardware and OS. I have a new M3 MBP and the only thing that works is the export DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib workaround. I have installed and linked cairo with brew as recommended, no error messages in that process. I am using Poetry in my own project, and there, the fallback workaround only seems to work if I run the export statement in the active Poetry shell. Exporting in the root shell and then building with poetry run mkdocs build also leads to the error. I am quite puzzled what the issue is, but maybe this description gives somebody an idea.

  11. squidfunk commented on Feb 19, 2024

    @squidfunk
    Owner

    I'm successfully running libcairo on my M2. Maybe the M3 is still too new? I'm not using the workaround. However, I'm not using Poetry but good ol' pip, which could be related.

  12. pflooky commented on Feb 22, 2024

    @pflooky

    Just got the same issue as above today on my Mac M1. Also using pip. Resolved via the same workaround. Maybe the cairo install via brew does not really "install" it but just provides the .so,.dylib,.dll' files as the error message states it cannot find the .so,.dylib,.dll' files in certain locations. Not sure about the python dependency ecosystem :D.

  13. nint8835 commented on Apr 7, 2024

    @nint8835

    I'm successfully running libcairo on my M2. Maybe the M3 is still too new? I'm not using the workaround. However, I'm not using Poetry but good ol' pip, which could be related.

    @squidfunk Are you by chance using a Homebrew version of Python? I've been looking into this issue for the past couple of hours and have found that Homebrew patches the Python source code to find Homebrew-installed libraries properly, whereas if you use Python installed any other way it does not have this patch.

    Reproduced with your troubleshooting script, you can see the difference in paths searched:

    System Python
    curl "https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/includes/debug/cairo-lookup-macos.py" | /usr/bin/python3 -
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  1303  100  1303    0     0   6735      0 --:--:-- --:--:-- --:--:--  6716
    Doesn't exist: libcairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/libcairo-2.dylib
    Doesn't exist: /usr/local/lib/libcairo-2.dylib
    Doesn't exist: /lib/libcairo-2.dylib
    Doesn't exist: /usr/lib/libcairo-2.dylib
    ---
    Doesn't exist: cairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/cairo-2.dylib
    Doesn't exist: /usr/local/lib/cairo-2.dylib
    Doesn't exist: /lib/cairo-2.dylib
    Doesn't exist: /usr/lib/cairo-2.dylib
    ---
    Doesn't exist: cairo-2.framework/cairo-2
    Doesn't exist: /Users/nint8835/lib/cairo-2
    Doesn't exist: /usr/local/lib/cairo-2
    Doesn't exist: /lib/cairo-2
    Doesn't exist: /usr/lib/cairo-2
    ---
    Doesn't exist: libcairo.dylib
    Doesn't exist: /Users/nint8835/lib/libcairo.dylib
    Doesn't exist: /usr/local/lib/libcairo.dylib
    Doesn't exist: /lib/libcairo.dylib
    Doesn't exist: /usr/lib/libcairo.dylib
    ---
    Doesn't exist: cairo.dylib
    Doesn't exist: /Users/nint8835/lib/cairo.dylib
    Doesn't exist: /usr/local/lib/cairo.dylib
    Doesn't exist: /lib/cairo.dylib
    Doesn't exist: /usr/lib/cairo.dylib
    ---
    Doesn't exist: cairo.framework/cairo
    Doesn't exist: /Users/nint8835/Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /Network/Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /System/Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /Users/nint8835/lib/cairo
    Doesn't exist: /usr/local/lib/cairo
    Doesn't exist: /lib/cairo
    Doesn't exist: /usr/lib/cairo
    ---
    Doesn't exist: liblibcairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/liblibcairo-2.dylib
    Doesn't exist: /usr/local/lib/liblibcairo-2.dylib
    Doesn't exist: /lib/liblibcairo-2.dylib
    Doesn't exist: /usr/lib/liblibcairo-2.dylib
    ---
    Doesn't exist: libcairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/libcairo-2.dylib
    Doesn't exist: /usr/local/lib/libcairo-2.dylib
    Doesn't exist: /lib/libcairo-2.dylib
    Doesn't exist: /usr/lib/libcairo-2.dylib
    ---
    Doesn't exist: libcairo-2.framework/libcairo-2
    Doesn't exist: /Users/nint8835/lib/libcairo-2
    Doesn't exist: /usr/local/lib/libcairo-2
    Doesn't exist: /lib/libcairo-2
    Doesn't exist: /usr/lib/libcairo-2
    ---
    The path is not found
    List of files that FFI will try to load:
    - libcairo.so.2
    - libcairo.2.dylib
    - libcairo-2.dll
    
    asdf-installed Python (my main install)
    curl "https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/includes/debug/cairo-lookup-macos.py" | python -
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  1303  100  1303    0     0   8066      0 --:--:-- --:--:-- --:--:--  8093
    Doesn't exist: libcairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/libcairo-2.dylib
    Doesn't exist: /usr/local/lib/libcairo-2.dylib
    Doesn't exist: /lib/libcairo-2.dylib
    Doesn't exist: /usr/lib/libcairo-2.dylib
    ---
    Doesn't exist: cairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/cairo-2.dylib
    Doesn't exist: /usr/local/lib/cairo-2.dylib
    Doesn't exist: /lib/cairo-2.dylib
    Doesn't exist: /usr/lib/cairo-2.dylib
    ---
    Doesn't exist: cairo-2.framework/cairo-2
    Doesn't exist: /Users/nint8835/lib/cairo-2
    Doesn't exist: /usr/local/lib/cairo-2
    Doesn't exist: /lib/cairo-2
    Doesn't exist: /usr/lib/cairo-2
    ---
    Doesn't exist: libcairo.dylib
    Doesn't exist: /Users/nint8835/lib/libcairo.dylib
    Doesn't exist: /usr/local/lib/libcairo.dylib
    Doesn't exist: /lib/libcairo.dylib
    Doesn't exist: /usr/lib/libcairo.dylib
    ---
    Doesn't exist: cairo.dylib
    Doesn't exist: /Users/nint8835/lib/cairo.dylib
    Doesn't exist: /usr/local/lib/cairo.dylib
    Doesn't exist: /lib/cairo.dylib
    Doesn't exist: /usr/lib/cairo.dylib
    ---
    Doesn't exist: cairo.framework/cairo
    Doesn't exist: /Users/nint8835/Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /Network/Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /System/Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /Users/nint8835/lib/cairo
    Doesn't exist: /usr/local/lib/cairo
    Doesn't exist: /lib/cairo
    Doesn't exist: /usr/lib/cairo
    ---
    Doesn't exist: liblibcairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/liblibcairo-2.dylib
    Doesn't exist: /usr/local/lib/liblibcairo-2.dylib
    Doesn't exist: /lib/liblibcairo-2.dylib
    Doesn't exist: /usr/lib/liblibcairo-2.dylib
    ---
    Doesn't exist: libcairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/libcairo-2.dylib
    Doesn't exist: /usr/local/lib/libcairo-2.dylib
    Doesn't exist: /lib/libcairo-2.dylib
    Doesn't exist: /usr/lib/libcairo-2.dylib
    ---
    Doesn't exist: libcairo-2.framework/libcairo-2
    Doesn't exist: /Users/nint8835/lib/libcairo-2
    Doesn't exist: /usr/local/lib/libcairo-2
    Doesn't exist: /lib/libcairo-2
    Doesn't exist: /usr/lib/libcairo-2
    ---
    The path is not found
    List of files that FFI will try to load:
    - libcairo.so.2
    - libcairo.2.dylib
    - libcairo-2.dll
    
    Homebrew Python
    curl "https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/includes/debug/cairo-lookup-macos.py" | /opt/homebrew/bin/python3 -
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  1303  100  1303    0     0   8766      0 --:--:-- --:--:-- --:--:--  8804
    Doesn't exist: libcairo-2.dylib
    Doesn't exist: /opt/homebrew/lib/libcairo-2.dylib
    Doesn't exist: /opt/homebrew/opt/openssl@3/lib/libcairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/libcairo-2.dylib
    Doesn't exist: /usr/local/lib/libcairo-2.dylib
    Doesn't exist: /lib/libcairo-2.dylib
    Doesn't exist: /usr/lib/libcairo-2.dylib
    ---
    Doesn't exist: cairo-2.dylib
    Doesn't exist: /opt/homebrew/lib/cairo-2.dylib
    Doesn't exist: /opt/homebrew/opt/openssl@3/lib/cairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/cairo-2.dylib
    Doesn't exist: /usr/local/lib/cairo-2.dylib
    Doesn't exist: /lib/cairo-2.dylib
    Doesn't exist: /usr/lib/cairo-2.dylib
    ---
    Doesn't exist: cairo-2.framework/cairo-2
    Doesn't exist: /opt/homebrew/lib/cairo-2
    Doesn't exist: /opt/homebrew/opt/openssl@3/lib/cairo-2
    Doesn't exist: /Users/nint8835/lib/cairo-2
    Doesn't exist: /usr/local/lib/cairo-2
    Doesn't exist: /lib/cairo-2
    Doesn't exist: /usr/lib/cairo-2
    ---
    Doesn't exist: libcairo.dylib
    Found: /opt/homebrew/lib/libcairo.dylib
    Doesn't exist: /opt/homebrew/opt/openssl@3/lib/libcairo.dylib
    Doesn't exist: /Users/nint8835/lib/libcairo.dylib
    Doesn't exist: /usr/local/lib/libcairo.dylib
    Doesn't exist: /lib/libcairo.dylib
    Doesn't exist: /usr/lib/libcairo.dylib
    ---
    Doesn't exist: cairo.dylib
    Doesn't exist: /opt/homebrew/lib/cairo.dylib
    Doesn't exist: /opt/homebrew/opt/openssl@3/lib/cairo.dylib
    Doesn't exist: /Users/nint8835/lib/cairo.dylib
    Doesn't exist: /usr/local/lib/cairo.dylib
    Doesn't exist: /lib/cairo.dylib
    Doesn't exist: /usr/lib/cairo.dylib
    ---
    Doesn't exist: cairo.framework/cairo
    Doesn't exist: /opt/homebrew/Frameworks/cairo.framework/cairo
    Doesn't exist: /Users/nint8835/Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /Network/Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /System/Library/Frameworks/cairo.framework/cairo
    Doesn't exist: /opt/homebrew/lib/cairo
    Doesn't exist: /opt/homebrew/opt/openssl@3/lib/cairo
    Doesn't exist: /Users/nint8835/lib/cairo
    Doesn't exist: /usr/local/lib/cairo
    Doesn't exist: /lib/cairo
    Doesn't exist: /usr/lib/cairo
    ---
    Doesn't exist: liblibcairo-2.dylib
    Doesn't exist: /opt/homebrew/lib/liblibcairo-2.dylib
    Doesn't exist: /opt/homebrew/opt/openssl@3/lib/liblibcairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/liblibcairo-2.dylib
    Doesn't exist: /usr/local/lib/liblibcairo-2.dylib
    Doesn't exist: /lib/liblibcairo-2.dylib
    Doesn't exist: /usr/lib/liblibcairo-2.dylib
    ---
    Doesn't exist: libcairo-2.dylib
    Doesn't exist: /opt/homebrew/lib/libcairo-2.dylib
    Doesn't exist: /opt/homebrew/opt/openssl@3/lib/libcairo-2.dylib
    Doesn't exist: /Users/nint8835/lib/libcairo-2.dylib
    Doesn't exist: /usr/local/lib/libcairo-2.dylib
    Doesn't exist: /lib/libcairo-2.dylib
    Doesn't exist: /usr/lib/libcairo-2.dylib
    ---
    Doesn't exist: libcairo-2.framework/libcairo-2
    Doesn't exist: /opt/homebrew/lib/libcairo-2
    Doesn't exist: /opt/homebrew/opt/openssl@3/lib/libcairo-2
    Doesn't exist: /Users/nint8835/lib/libcairo-2
    Doesn't exist: /usr/local/lib/libcairo-2
    Doesn't exist: /lib/libcairo-2
    Doesn't exist: /usr/lib/libcairo-2
    ---
    The path is /opt/homebrew/lib/libcairo.dylib
    List of files that FFI will try to load:
    - /opt/homebrew/lib/libcairo.dylib
    - libcairo.so.2
    - libcairo.2.dylib
    - libcairo-2.dll
    

    For my needs, explicitly using the Homebrew Python for mkdocs (by creating a virtualenv with /opt/homebrew/bin/python3 -m venv venv) was the simplest fix that allows me to avoid needing to use DYLD_FALLBACK_LIBRARY_PATH every time, but this should also be permanently solvable by copying/symlinking the library into ~/lib or /usr/local/lib

  14. squidfunk commented on Apr 8, 2024

    @squidfunk
    Owner

    Are you by chance using a Homebrew version of Python?

    Yes, I'm using the Homebrew version of Python. Thanks for sharing more intel on this problem, we should definitely add this to our documentation (cc @katharinalisalin)

  15. Light2Dark commented on Jan 23, 2025

    @Light2Dark

    I had this issue too (MBP3), and the suggested workaround didn't work, it kept trying to find the files in a diff. path. I am using hatch though (diff project).

    my solution was to symlink the curr project directory & where the files were.
    ln -s /opt/homebrew/lib/libcairo.2.dylib .

  16. dmadisetti commented on May 10, 2025

    @dmadisetti

    There's something about OSx stripping explicit DYLD paths that makes this tricky to use with hatch, but might be more of a hatch problem than a mkdocs problem

  17. kylifornication-code commented on Jun 23, 2025

    @kylifornication-code

    Hitting this issue on my M4 MBP also. The workaround worked fine.

  18. sdargoeuves commented on Oct 6, 2025

    @sdargoeuves

    I had this issue too (MBP3), and the suggested workaround didn't work, it kept trying to find the files in a diff. path. I am using hatch though (diff project).

    my solution was to symlink the curr project directory & where the files were. ln -s /opt/homebrew/lib/libcairo.2.dylib .

    thank you for this fix/workaround, I prefer it to the export option which I would have to re-enter every time, or insert to my venv (or to my ~/.xxxrc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugupstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions