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

2

6

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?

Grumble answered 15/6, 2019 at 5:56 Comment(7)
do you use this one brew install pkg-config to install pkg-config package?Looksee
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...Grumble
@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?Grumble
pycairo are just Python bindings to cairo package. Install it first via Homebrew: brew install cairoLeda
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.Grumble
If a package provides binary wheels they usually contain everything; see for example for how many different platforms Cheetah3 was compiled. But pycairo provides only source distribution 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).Artless
try to install cairo package through brew then try your pip install pycairo. I think it could help you.Linotype
S
4

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
Synecology answered 14/1, 2022 at 5:6 Comment(2)
Not massively helpful for an OSX (Mac) question.Colby
Also works on Ubuntu!Ipecac
R
4

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
Rumen answered 7/6, 2022 at 17:59 Comment(1)
Faced with it on use llama_index download_loader('ConfluenceReader'). Successfully fixed.Stockist

© 2022 - 2024 — McMap. All rights reserved.