cairocffi: "No package 'libffi' found" error during pip install

When I tried to pip install cairocffi into a fresh virtualenv, I got an error saying “Package libffi was not found…”

$ mkvirtualenv tmp
New python executable in tmp/bin/python
Installing setuptools............done.
Installing pip...............done.

(tmp)$ pip install cairocffi
Downloading/unpacking cairocffi
  Downloading cairocffi-0.5.tar.gz (70kB): 70kB downloaded
  Running setup.py egg_info for package cairocffi

    no previously-included directories found matching 'docs/_build'
Downloading/unpacking cffi>=0.6 (from cairocffi)
  Downloading cffi-0.6.tar.gz (169kB): 169kB downloaded
  Running setup.py egg_info for package cffi
    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
    No package 'libffi' found
    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
    No package 'libffi' found
    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
    No package 'libffi' found
    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
    No package 'libffi' found
    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
    No package 'libffi' found

Downloading/unpacking pycparser (from cffi>=0.6->cairocffi)
  Downloading pycparser-2.09.1.tar.gz (201kB): 201kB downloaded
  Running setup.py egg_info for package pycparser

Installing collected packages: cairocffi, cffi, pycparser
  Running setup.py install for cairocffi

    no previously-included directories found matching 'docs/_build'
  Running setup.py install for cffi
    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
    No package 'libffi' found
    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
    No package 'libffi' found
    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
    No package 'libffi' found
    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
    No package 'libffi' found
    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
    No package 'libffi' found
    building '_cffi_backend' extension
    /usr/bin/gcc-4.2 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -pipe -no-cpp-precomp -pipe -arch x86_64 -I/usr/include/ffi -I/usr/include/libffi -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c c/_cffi_backend.c -o build/temp.macosx-10.7-x86_64-2.7/c/_cffi_backend.o
    llvm-gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -Wl,-F. -bind_at_load -pipe -no-cpp-precomp -arch x86_64 build/temp.macosx-10.7-x86_64-2.7/c/_cffi_backend.o -lffi -o build/lib.macosx-10.7-x86_64-2.7/_cffi_backend.so

  Running setup.py install for pycparser

Successfully installed cairocffi cffi pycparser
Cleaning up...

(tmp) $ python --version
Python 2.7.1

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 21 (4 by maintainers)

Most upvoted comments

Hi. cairocffi uses CFFI, which itself requires libffi. What OS / distribution is this? You probably need to install the python-dev and libffi-dev packages.

For anyone who comes across this and it running CentOS 6 or 7, I needed to install an additional package before attempting to install Ansible using pip. yum install libffi-devel

For ubuntu it goes like: sudo apt-get install python-cffi.

// , For those of us coming to this from an attempted Python package installation to CEntOS 6.7, make sure you have the python-cffi system package installed to CEntOS 6.3, by

$ sudo yum search ffi | grep python

The most likely looking result was python-cffi.x86_64.

$ sudo yum install python-cffi

In my case, on Ubuntu Server 14.04.4 LTS, this is what cleared up my problem today: pip install --upgrade cffi

that fixed for me by : apt install libffi-dev in ubuntu 18

in my case, this solved by bellow: pip install separately

  1. pip install cffi
  2. pip install cairocffi server info: Ubuntu 14.04.1 LTS

Alpine: apk add --update libffi

For osx I had to export PKG_CONFIG_PATH of the libffi installed under brew as mentioned in http://stackoverflow.com/a/25854749/1489188

It’s sudo apt-get install -y python3-cffi for Python 3 on Ubuntu 16.04 LTS.

As mentioned before, cairocffi uses CFFI, which itself requires libffi. When CFFI is being installed (possibly automatically as a dependency of cairocffi) from source (as pip typically does, since https://pypi.python.org/pypi/cffi doesn’t have pre-compiled .whl files for Linux), it will compile its C component and try to find the required libffi header files.

Installing a system package for CFFI may be enough (even if you end up building CFFI again in a virtualenv) since it may install libffi as a dependency somewhere virtualenv-CFFI can find it. Some distributions (like Debian and Ubuntu) split lib_-dev packages (for header files) from lib_, so you may still need to install libffi-dev separately.

For Alpine: apk add --update --no-cache g++ gcc libxml2-dev libxslt-dev python-dev libffi-dev openssl-dev make

// , Ah, yes, and I think we must make sure to have that installed before using the related Python bindings.