Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation on macOS (15.1/Catalina) (M1) fails with cairo not found. #387

Open
ChillarAnand opened this issue Nov 11, 2024 · 1 comment

Comments

@ChillarAnand
Copy link

I have already installed the pre-requisites.

Screenshot 2024-11-11 at 10 18 36

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.
@Tomaubier
Copy link

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):

  1. Check the location of a missing library by running find /opt -name <library name>.pc in the terminal.
    eg. find /opt -name cairo.pc gave me: /opt/homebrew/Cellar/cairo/1.18.2/lib/pkgconfig/cairo.pc
    If the library is not installed on your system, no paths will be returned by the command. Install the package using brew install <library name> and try again.

  2. Add the library path to PKG_CONFIG_PATH
    export 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"

  3. In the same terminal session check that pkg-config finds the library by running pkg-config --libs <lib name>
    eg. pkg-config --libs cairo

  4. 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 to PKG_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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants