Python 在 OS X 上使用 pip 安装 bcrypt 时出错:找不到 ffi.h(安装了 libffi)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22875270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error installing bcrypt with pip on OS X: can't find ffi.h (libffi is installed)
提问by Cody
I'm getting this error when trying to install bcrypt with pip. I have libffi installed in a couple places (the Xcode OS X SDK, and from homebrew), but I don't know how to tell pip to look for it. Any suggestions?
尝试使用 pip 安装 bcrypt 时出现此错误。我在几个地方(Xcode OS X SDK 和自制软件)安装了 libffi,但我不知道如何告诉 pip 查找它。有什么建议?
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
采纳答案by nathancahill
Without using sudo and CFLAGS and CPPFLAGS (unnecessary for pip):
不使用 sudo 和 CFLAGS 和 CPPFLAGS(pip 不需要):
$ brew install pkg-config libffi
$ export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/
$ pip install bcrypt
回答by Cody
回答by Zach Young
Update 26/Aug/15
15 年 8 月 26 日更新
I think TA's answer is better in that it's handled by the system.
我认为 TA 的答案更好,因为它由系统处理。
First off, I'm loathe to install Brew or Ports, but that's another issue.
首先,我不愿意安装 Brew 或 Ports,但这是另一个问题。
I've been trying to pip install cryptography
, which depends on cffi, which imports ffi.h
.
我一直在尝试pip install cryptography
,这取决于 cffi,它导入ffi.h
.
I am curious why no one addressed that he (and me, and I believe others) have ffi
installed with Xcode:
我很好奇为什么没有人提到他(和我,以及我相信其他人)已经ffi
安装了 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:
因为该错误专门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
I have ffi.h
, it's just that the system thinks it should be in /usr/include/...
.
我有ffi.h
,只是系统认为它应该在/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:
我的/usr/include
目录恰好是空的,并且没有链接到任何东西,所以我只是将有问题的目录/文件链接到了找不到它的地方:
ln -fs {THAT_XCODE_SDK_FFI_PATH_FROM_ABOVE} /usr/include/ffi
I can now install and build cffi and cryptography.
我现在可以安装和构建 cffi 和密码学。
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.
在理解构建链/链接动态方面,我非常新手,如果这很糟糕,我不明白……所以,请告诉我。
回答by 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 已经为我安装了(如问题本身所述,它确实提供了 ffi.h 标头),但由于某种原因没有填充 /usr/include (如 Zachary Young 提到的)。我四处寻找为什么没有填充 /usr/include 并发现以下命令修复了它:
$ xcode-select --install