Reputation: 118
I have been trying to install pycairo with pip3 on MacOs but whenever y try to do so this error appears:
pip3 install pycairo
Collecting pycairo
Using cached https://files.pythonhosted.org/packages/48/20/5e83af98eb897935bf7dc39455e892ba866feebb9b7c3b392982866f9958/pycairo-1.18.1.tar.gz
Installing collected packages: pycairo
Running setup.py install for pycairo ... error
ERROR: Complete output from command /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-install-uiqmlfkz/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-record-egwlnpkb/install-record.txt --single-version-externally-managed --compile:
ERROR: running install
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.7
creating build/lib.macosx-10.9-x86_64-3.7/cairo
copying cairo/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/cairo
copying cairo/__init__.pyi -> build/lib.macosx-10.9-x86_64-3.7/cairo
copying cairo/py.typed -> build/lib.macosx-10.9-x86_64-3.7/cairo
running build_ext
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libffi', required by 'gobject-2.0', not found
Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']' returned non-zero exit status 1.
----------------------------------------
ERROR: Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-install-uiqmlfkz/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-record-egwlnpkb/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-install-uiqmlfkz/pycairo/
I have installed cairo and pkg-config using brew.
Update, i did set the path of PKG_CONFIG_PATH using the following command
export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.2.1/lib/pkgconfig/
And later using pip3 to install pycairo it does the job. The only thing is that even if it is installed now python3 doest not find pycairo.
python3
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycairo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pycairo'
I have the following installed with brew
brew list
aom jpeg p11-kit
atk lame pango
cairo leptonica pcre
ffmpeg libass pixman
flac libbluray pkg-config
fontconfig libevent python
freetype libffi readline
frei0r libogg rtmpdump
fribidi libpng rubberband
gdbm libsamplerate sdl2
gdk-pixbuf libsndfile snappy
gettext libsoxr speex
ghostscript libtasn1 sqlite
giflib libtiff tesseract
glew libunistring theora
glib libvorbis unbound
gmp libvpx webp
gnutls little-cms2 x264
graphite2 nettle x265
gtk+ opencore-amr xvid
harfbuzz openjpeg xz
hicolor-icon-theme openssl
icu4c opus
and this is my pip3 list
astroid 2.2.5
cairocffi 1.0.2
cffi 1.12.3
isort 4.3.16
lazy-object-proxy 1.3.1
mccabe 0.6.1
opencv-python 3.4.2.17
pip 19.1
pycairo 1.18.1 #it seems like it's installed but it doesn't recognize it whenever I try to import it
pycparser 2.19
pylint 2.3.1
setuptools 40.8.0
typed-ast 1.3.1
wrapt 1.11.1
Upvotes: 1
Views: 2390
Reputation: 1095
Had the same problem.
Solution:
Keep your python3 and libffi installed via brew. Only do this before installing cairo:
export LDFLAGS="-L/usr/local/opt/libffi/lib"
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
Now go ahead and run pip:
pip3 install --user pycairo
Everything should work after this.
Tested on macOS 10.14.6, python 3.7.4 installed via brew, libffi 3.2.1 installed via brew.
Upvotes: 2
Reputation: 40894
You have the answer right there in the pip3
output:
Package 'libffi', required by 'gobject-2.0', not found
On macOS, brew install libffi
should do it.
(Also, of course, installing anything into the system Python, and not inside a virtualenv, is usually a bad idea.)
Upvotes: 0