Installation on macOS (15.1/Catalina) (M1) fails with cairo not found.
I have already installed the pre-requisites.
But during install, it is failing to find "cairo".
Compiler for C supports arguments -Wswitch-default: YES
Compiler for C supports arguments -Wno-missing-field-initializers: YES
Compiler for C supports arguments -Wno-unused-parameter: YES
Compiler for C supports arguments -fno-strict-aliasing: YES
Compiler for C supports arguments -fvisibility=hidden: YES
Found pkg-config: YES (/opt/local/bin/pkg-config) 0.29.2
Found CMake: /Users/chillaranand/homebrew/bin/cmake (3.30.3)
Run-time dependency cairo found: NO (tried pkgconfig, framework and cmake)
../cairo/meson.build:31:12: ERROR: Dependency "cairo" not found, tried pkgconfig, framework and cmake
A full log can be found at /private/var/folders/vb/3wyl_42s4x1_z_7swgpq9xr40000gq/T/pip-install-dr_abefi/pycairo_8e2c36b9f63e490084503233417555c7/.mesonpy-joompwi1/meson-logs/meson-log.txt
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
Just found a fix for the same issue occurring with macOS 15.1.1, on a clean Python 3.12.7 miniconda environment.
Based on this comment I managed to defined a proper PKG_CONFIG_PATH that solved the issue. The process is a bit cumbersome though so a more long term solution is still needed.
Here s a quick run down of the procedure I had to go through for some libraries (cairo, fontconfig, freetype2, x11 and xcb in my case):
-
Check the location of a missing library by running
find /opt -name <library name>.pcin the terminal. eg.find /opt -name cairo.pcgave me:/opt/homebrew/Cellar/cairo/1.18.2/lib/pkgconfig/cairo.pcIf the library is not installed on your system, no paths will be returned by the command. Install the package usingbrew install <library name>and try again. -
Add the library path to
PKG_CONFIG_PATHexport PKG_CONFIG_PATH="<parent directory path of the missing lib>:$PKG_CONFIG_PATH"eg.export PKG_CONFIG_PATH="/opt/homebrew/Cellar/cairo/1.18.2/lib/pkgconfig/:$PKG_CONFIG_PATH" -
In the same terminal session check that
pkg-configfinds the library by runningpkg-config --libs <lib name>eg.pkg-config --libs cairo -
Try installing
pycairo(pip install pycairo), if the errors pops back up with a different package, repeat the process and append the new package path toPKG_CONFIG_PATH.
For reference, by the time I managed to get pycairo installed, my PKG_CONFIG_PATH looked like this:
export PKG_CONFIG_PATH="/opt/homebrew/Cellar/cairo/1.18.2/lib/pkgconfig/:/opt/homebrew/Cellar/fontconfig/2.15.0/lib/pkgconfig/:/opt/homebrew/Cellar/freetype/2.13.3/lib/pkgconfig/:/opt/homebrew/Cellar/libx11/1.8.10/lib/pkgconfig/:/opt/homebrew/share/pkgconfig/:/opt/homebrew/lib/pkgconfig/:$PKG_CONFIG_PATH"
I also this export command to my terminal config file (nano ~/.zshrc) in case I need to reinstall pycairo in an other environment.
I hope that helps!
I don't have homebrew, so I don't know why your setup behaves that way.
At least in CI installing pkg-config and cairo in homebrew makes both work without any extra work. And the upstream cairo packages also has a test that checks that pkg-config works: https://github.com/Homebrew/homebrew-core/blob/a3e8d833026c88e9be15814b96ce80289b490abc/Formula/c/cairo.rb#L76
So all that stuff above should not be needed.. somehow.
If someone has any idea let me know.