pip install pycairo fails on osx: 'pkg-config' search path problems

Viewed 2918

I've been trying to install pycairo on a mac os x. I'm getting an error message,

Initially I was getting 'pkg-config' not found. After installing that through brew, I get Package cairo was not found in the pkg-config search path. In principle I could try to edit the search path, but since this is going through pip, I would have expected this to be all taken care of. Is there a way to tell pip to put the stuff where pkg-config knows to look?

Here's the full message.

> pip install pycairo
Collecting pycairo
  Using cached https://files.pythonhosted.org/packages/48/20/5e83af98eb897935bf7dc39455e892ba866feebb9b7c3b392982866f9958/pycairo-1.18.1.tar.gz
Building wheels for collected packages: pycairo
  Building wheel for pycairo (setup.py) ... error
  ERROR: Complete output from command /Applications/anaconda/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/f2/bzrj46j11gzdk19j91tp1sq80000gq/T/pip-install-lahb8lq4/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/f2/bzrj46j11gzdk19j91tp1sq80000gq/T/pip-wheel-scnvplas --python-tag cp36:
  ERROR: running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.7-x86_64-3.6
  creating build/lib.macosx-10.7-x86_64-3.6/cairo
  copying cairo/__init__.py -> build/lib.macosx-10.7-x86_64-3.6/cairo
  copying cairo/__init__.pyi -> build/lib.macosx-10.7-x86_64-3.6/cairo
  copying cairo/py.typed -> build/lib.macosx-10.7-x86_64-3.6/cairo
  running build_ext
  Package cairo was not found in the pkg-config search path.
  Perhaps you should add the directory containing `cairo.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'cairo' found
  Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']' returned non-zero exit status 1.
  ----------------------------------------
  ERROR: Failed building wheel for pycairo

I get the same error if I use pip to install an older version.

There is a similar question here: How can I fix the problem when installing pycairo on windows?, but it's related to Windows, and the error looks to be different to me (also I'm not satisfied by the answer).

Any suggestion for how to fix this?

2 Answers

I ran into this issue too.

I am using Q4OS(Debian), and do not have brew.

Here is these steps I manage to solve this issue.

sudo apt-get update -y
sudo apt-get install -y pkg-config
sudo apt-get install libcairo2-dev libjpeg-dev libgif-dev
sudo pip install pycairo

I could solve the issue with the help of the comments from the question. In summary:

brew install pkg-config
brew install cairo
pip install pycairo
Related