Solution to no library called cairo-2 was found error¶
The error¶
I encountered the error no library called "cairo-2" was found
when trying to install something related to mkdocs-material (specifically, mkdocs-material-insiders). The full error looked like this:
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), '/usr/local/lib/libcairo.so.2' (no such file), '/usr/lib/libcairo.so.2' (no such file), '/Users/soma/Development/mkdocs-material-insiders/libcairo.so.2' (no such file), '/usr/local/lib/libcairo.so.2' (no such file), '/usr/lib/libcairo.so.2' (no such file)
cannot load library 'libcairo.2.dylib': dlopen(libcairo.2.dylib, 0x0002): tried: 'libcairo.2.dylib' (no such file), '/usr/local/lib/libcairo.2.dylib' (no such file), '/usr/lib/libcairo.2.dylib' (no such file), '/Users/soma/Development/mkdocs-material-insiders/libcairo.2.dylib' (no such file), '/usr/local/lib/libcairo.2.dylib' (no such file), '/usr/lib/libcairo.2.dylib' (no such file)
cannot load library 'libcairo-2.dll': dlopen(libcairo-2.dll, 0x0002): tried: 'libcairo-2.dll' (no such file), '/usr/local/lib/libcairo-2.dll' (no such file), '/usr/lib/libcairo-2.dll' (no such file), '/Users/soma/Development/mkdocs-material-insiders/libcairo-2.dll' (no such file), '/usr/local/lib/libcairo-2.dll' (no such file), '/usr/lib/libcairo-2.dll' (no such file)
The difficult thing was I had already installed cairo using homebrew with brew install cairo
. macOS just couldn't find it! Luckily the error listed the places it was looking for cairo:
'libcairo.2.dylib'
(no such file)'/usr/local/lib/libcairo.2.dylib'
(no such file)'/usr/lib/libcairo.2.dylib'
(no such file)'/Users/soma/Development/mkdocs-material-insiders/libcairo.2.dylib'
(no such file)'/usr/local/lib/libcairo.2.dylib'
(no such file)'/usr/lib/libcairo.2.dylib'
(no such file)
The solution¶
To solve the problem, I just made a link from the current folder to the homebrew cairo located in /opt/homebrew/lib/libcairo.2.dylib
.
I ran the command again and it worked perfectly!