Error installing bcrypt with pip on OS X: can't find ffi.h (libffi is installed)

余生颓废 提交于 2019-11-27 17:23:55

Without using sudo and CFLAGS and CPPFLAGS (unnecessary for pip):

$ brew install pkg-config libffi
$ export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/
$ pip install bcrypt
Cody

I finally got it working with the following with a little help from these posts:

brew install pkg-config libffi
sudo bash
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/
pip install bcrypt
T A

Xcode was already installed for me (as mentioned in the question itself that it does provide the ffi.h header), but for some reason that didn't populate /usr/include (as Zachary Young mentioned). I dug around to see why the /usr/include wasn't populated and found that the following command fixed it:

$ xcode-select --install

Missing /usr/include after Yosemite and Xcode install?

Update 26/Aug/15

I think TA's answer is better in that it's handled by the system.


First off, I'm loathe to install Brew or Ports, but that's another issue.

I've been trying to pip install cryptography, which depends on cffi, which imports ffi.h.

I am curious why no one addressed that he (and me, and I believe others) have ffi installed with Xcode:

locate ffi.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/ffi/ffi.h

since the error is specifically about "not finding" ffi.h with the following build command:

c/_cffi_backend.c:14:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
...
...
/usr/bin/clang ...{omitted}... I/usr/include/ffi -I/usr/include/libffi

I have ffi.h, it's just that the system thinks it should be in /usr/include/....

My /usr/include directory happens to be empty, and not linked to anything, so I just linked the directory/file in question, to the place where it's not being found:

ln -fs {THAT_XCODE_SDK_FFI_PATH_FROM_ABOVE} /usr/include/ffi

I can now install and build cffi and cryptography.

I'm very novice when it comes to understanding build-chain/linking dynamics, and if this is bad, I don't get it... so, please let me know.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!