5

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?

Joel
  • 22,598
  • 6
  • 69
  • 93
  • do you use this one `brew install pkg-config` to install pkg-config package? – Manjeet Thakur Jun 15 '19 at 06:22
  • Don't have `brew` on my machine. I've always used pip to install python packages. Haven't encountered pkg-config, so I assumed it was some form of config file coming with pycairo... Google now tells me it's more than that... – Joel Jun 15 '19 at 06:27
  • @ManjeetThakur At risk of this turning into a "chameleon question", I've now installed pkg-config, and the new error is `Package cairo was not found in the pkg-config search path.` I'm editing the question to include this. Do you have a suggestion for how I can fix this to work within pip? – Joel Jun 15 '19 at 06:49
  • `pycairo` are just Python bindings to `cairo` package. Install it first via Homebrew: `brew install cairo` – hoefling Jun 15 '19 at 07:04
  • So the issue is that I just assumed pip would install everything needed (and didn't realize I'd need to install cairo separately). Thanks to both. – Joel Jun 15 '19 at 09:11
  • If a package provides binary wheels they usually contain everything; see for example for how many different platforms [Cheetah3](https://pypi.org/project/Cheetah3/#files) was compiled. But pycairo [provides only source distribution](https://pypi.org/project/pycairo/#files) so `pip` has to compile it and for compilation it needs a lot of dependencies: a compiler, libraries, development files for the libraries (header/include files, `pkg-config` configuration). – phd Jun 15 '19 at 13:56
  • try to install `cairo` package through `brew` then try your `pip install pycairo`. I think it could help you. – AbdolHosein Oct 30 '19 at 20:09

2 Answers2

3

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
Cuong Vo
  • 648
  • 9
  • 12
2

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
jiqir3n
  • 21
  • 1
  • 1
  • 4