在OS X上用pip安装bcrypt时出错:找不到ffi.h(安装了libffi)
我试图用pip安装bcrypt时遇到这个错误。 我在几个地方安装了libffi(Xcode OS X SDK和自制软件),但是我不知道如何告诉pip来寻找它。 有什么build议么?
Downloading/unpacking bcrypt==1.0.2 (from -r requirements.txt (line 41)) Running setup.py egg_info for package bcrypt OS/X: confusion between 'cc' versus 'gcc' (see issue 123) will not use '__thread' in the C code c/_cffi_backend.c:14:10: fatal error: 'ffi.h' file not found #include <ffi.h> ^ 1 error generated. Traceback (most recent call last): File "<string>", line 16, in <module> File "/Users/cody/virtualenvs/analytics/build/bcrypt/setup.py", line 104, in <module> "Programming Language :: Python :: 3.3", File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 112, in setup _setup_distribution = dist = klass(attrs) File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 239, in __init__ File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 264, in fetch_build_eggs File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 620, in resolve dist = best[req.key] = env.best_match(req, ws, installer) File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 858, in best_match return self.obtain(req, installer) # try and download/install File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 870, in obtain return installer(requirement) File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 314, in fetch_build_egg File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 593, in easy_install File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 623, in install_item File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 811, in install_eggs File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 1017, in build_and_install File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 1005, in run_setup distutils.errors.DistutilsError: Setup script exited with error: command 'cc' failed with exit status 1 Complete output from command python setup.py egg_info: OS/X: confusion between 'cc' versus 'gcc' (see issue 123) will not use '__thread' in the C code c/_cffi_backend.c:14:10: fatal error: 'ffi.h' file not found #include <ffi.h> ^ 1 error generated. Traceback (most recent call last): File "<string>", line 16, in <module> File "/Users/cody/virtualenvs/analytics/build/bcrypt/setup.py", line 104, in <module> "Programming Language :: Python :: 3.3", File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 112, in setup _setup_distribution = dist = klass(attrs) File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 239, in __init__ File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 264, in fetch_build_eggs File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 620, in resolve dist = best[req.key] = env.best_match(req, ws, installer) File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 858, in best_match return self.obtain(req, installer) # try and download/install File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 870, in obtain return installer(requirement) File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 314, in fetch_build_egg File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 593, in easy_install File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 623, in install_item File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 811, in install_eggs File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 1017, in build_and_install File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 1005, in run_setup distutils.errors.DistutilsError: Setup script exited with error: command 'cc' failed with exit status 1 ---------------------------------------- Command python setup.py egg_info failed with error code 1 in /Users/cody/virtualenvs/analytics/build/bcrypt
不使用sudo和CFLAGS和CPPFLAGS(不必要的点数):
$ brew install pkg-config libffi $ export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/ $ pip install bcrypt
我终于通过这些 post得到了一些帮助:
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
Xcode已经为我安装了(正如问题中提到的那样,它提供了ffi.h头文件),但由于某些原因,没有填充/ usr / include(就像Zachary Young提到的那样)。 我深入了解了为什么/ usr / include没有被填充,并发现下面的命令修复了它:
$ xcode-select --install
Yosemite和Xcode安装后缺less/ usr / include?
更新26 / Aug / 15
我觉得TA的答案更好,因为它是由系统处理的。
首先,我不喜欢安装Brew或Ports,但这是另一个问题。
我一直在试图pip install cryptography
,这取决于cffi,它导入ffi.h
我很好奇为什么没有人说他(和我,我相信其他人)已经安装了Xcode:
locate ffi.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/ffi/ffi.h
因为这个错误是关于“找不到” ffi.h
,具体如下:
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
我有ffi.h
,只是系统认为它应该在/usr/include/...
。
我的/usr/include
目录恰好是空的,没有链接到任何东西,所以我只是把目录/文件链接到没有被find的地方:
ln -fs {THAT_XCODE_SDK_FFI_PATH_FROM_ABOVE} /usr/include/ffi
我现在可以安装和构buildcffi和encryption。
对于理解构build链/链接dynamic,我是非常新手,如果这样做不好,我不明白…所以,请让我知道。