PIP install unable to find ffi.h even though it recognizes libffi

PythonLinuxPip

Python Problem Overview


I have installed libffi on my Linux server as well as correctly set the PKG_CONFIG_PATH environment variable to the correct directory, as pip recognizes that it is installed; however, when trying to install pyOpenSSL, pip states that it cannot find file 'ffi.h'. I know both thatffi.h exists as well as its directory, so how do I go about closing this gap between ffi.h and pip?

Python Solutions


Solution 1 - Python

You need to install the development package as well.

libffi-dev on Debian/Ubuntu, libffi-devel on Redhat/Centos/Fedora.

Solution 2 - Python

To add to mhawke's answer, usually the Debian/Ubuntu based systems are "-dev" rather than "-devel" for RPM based systems

So, for Ubuntu it will be apt-get install libffi libffi-dev

RHEL, CentOS, Fedora (up to v22) yum install libffi libffi-devel

Fedora 23+ dnf install libffi libffi-devel

OSX/MacOS (assuming homebrew is installed) brew install libffi

Solution 3 - Python

You can use CFLAGS (and LDFLAGS or various other compiler and linker options) in front of the pip command (ditto for setup.py):

Something similar to the following should work:

CFLAGS=-I/usr/include/libffi/include pip install pyOpenSSL

Solution 4 - Python

Ubuntu/Mint

sudo apt-get install libffi6 libffi-dev 

Solution 5 - Python

pip packages usually don't use pkg-config. Therefore, you should set CFLAGS and LDFLAGS manually:

CFLAGS=$(pkg-config --cflags libffi) LDFLAGS=$(pkg-config --libs libffi) pip install pyOpenSSL

Solution 6 - Python

On Debian,

apt-get install libffi-dev

Solution 7 - Python

on CentOS:

yum install libffi-devel

Solution 8 - Python

You need to install the development package for libffi.

On RPM based systems (Fedora, Redhat, CentOS etc) the package is named libffi-devel.

Not sure about Debian/Ubuntu systems, I'm sure someone else will pipe up with that.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDonutGazView Question on Stackoverflow
Solution 1 - PythonLennart RegebroView Answer on Stackoverflow
Solution 2 - PythonChrisNView Answer on Stackoverflow
Solution 3 - Pythonuser707650View Answer on Stackoverflow
Solution 4 - PythonJulio Cezar RiffelView Answer on Stackoverflow
Solution 5 - PythonnneonneoView Answer on Stackoverflow
Solution 6 - PythonVolker KerkhoffView Answer on Stackoverflow
Solution 7 - PythonRoozbeh ZabihollahiView Answer on Stackoverflow
Solution 8 - PythonmhawkeView Answer on Stackoverflow