PIP install 无法找到 ffi.h,即使它识别 libffi

我已经在我的 Linux 服务器上安装了 libffi,并且正确地将 PKG_CONFIG_PATH环境变量设置到了正确的目录,因为 pip认识到它已经安装了,但是,当尝试安装 pyOpenSSL 时,pip 声明它无法找到“ ffi.h”文件。我知道 ffi.h既存在也存在它的目录,那么我该如何弥补 ffi.hpip之间的这个差距呢?

96894 次浏览

You need to install the development package as well.

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

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

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.

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

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

On Debian,

apt-get install libffi-dev

on CentOS:

yum install libffi-devel

Ubuntu/Mint

sudo apt-get install libffi6 libffi-dev