You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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:
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.
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.
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.
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.
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:
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
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)
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 .
Reacted by Seb d'Argoeuves, vincent d warmerdam and Akshay Agrawal
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
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)
Activity
squidfunk commentedon Feb 28, 2023
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:
I just installed
cairowith the method mentioned in the docs (usingbrew). 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.bilal-fazlani commentedon Jul 31, 2023
@bigmike36c did you ever find the cause of this? I am setting a new M1 Mac and running into same issue.
bigmike36c commentedon Jul 31, 2023
No, unfortunately I was never able to resolve this issue on my Mac.
jeichenseerNRX commentedon Sep 25, 2023
@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/libsquidfunk commentedon Sep 26, 2023
@jeichenseerNRX I think you just need to run
brew link cairo– that should create the symbolic links:squidfunk commentedon Sep 26, 2023
I wonder however, why Homebrew didn't do that when you installed it. Was there some kind of error message?
electronick-co commentedon Nov 27, 2023
I had the same issue on windows, solved it with these lines:
pip install pipwin
pipwin install cairocffi
slobentanzer commentedon Feb 19, 2024
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/libworkaround. 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 withpoetry run mkdocs buildalso leads to the error. I am quite puzzled what the issue is, but maybe this description gives somebody an idea.squidfunk commentedon Feb 19, 2024
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.
pflooky commentedon Feb 22, 2024
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.nint8835 commentedon Apr 7, 2024
@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
asdf-installed Python (my main install)
Homebrew Python
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 useDYLD_FALLBACK_LIBRARY_PATHevery time, but this should also be permanently solvable by copying/symlinking the library into~/libor/usr/local/libsquidfunk commentedon Apr 8, 2024
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)
Light2Dark commentedon Jan 23, 2025
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
hatchthough (diff project).my solution was to symlink the curr project directory & where the files were.
ln -s /opt/homebrew/lib/libcairo.2.dylib .dmadisetti commentedon May 10, 2025
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
kylifornication-code commentedon Jun 23, 2025
Hitting this issue on my M4 MBP also. The workaround worked fine.
sdargoeuves commentedon Oct 6, 2025
thank you for this fix/workaround, I prefer it to the
exportoption which I would have to re-enter every time, or insert to my venv (or to my ~/.xxxrc)