Table of Contents
Introduction
TL;DR
Use the following soft link soved my issue:
sudo ln -s /opt/homebrew/Cellar/cairo/1.18.2/lib/libcairo.dylib /usr/local/lib/libcairo.dylib
Enviornment
python 3.12
Mac M1 Chip, Sonoma 14.7.1
Homebrew version 4.4.6
pycairo 1.18.2
Detail
I encountered the following error:
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), '/usr/lib/libcairo.so.2' (no such file, not in dyld cache), 'libcairo.so.2' (no such file). 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), '/usr/lib/libcairo.2.dylib' (no such file, not in dyld cache), 'libcairo.2.dylib' (no such file). 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), '/usr/lib/libcairo-2.dll' (no such file, not in dyld cache), 'libcairo-2.dll' (no such file). Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo-2.dll'
I have no luck in solving the following error after using this solution possible because something do not work on my mac:
add below line to bash or zsh
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/opt/homebrew/lib/pkgconfig:$PKG_CONFIG_PATH"
export DYLD_LIBRARY_PATH="/usr/local/lib:/opt/homebrew/lib:$DYLD_LIBRARY_PATH"
source ~/.bash_profile or zsh_profile
Look back to the error carefully , the error seems failing after searching several optional paths, so I choosed to soft link libcairo.dylib and the issue resolved!
References
Happy Coding!