在OSX上安装pip cffi包失败

27

我正在为加密和Jasmin安装安装cffi包。

在发布问题之前,我进行了一些研究,因此找到了以下选项,但似乎不起作用:

系统

Mac OSx 10.9.5

python2.7

错误

c/_cffi_backend.c:13:10: fatal error: 'ffi.h' file not found

#include <ffi.h>

         ^

1 warning and 1 error generated.

请帮我解决以下问题。

谢谢

命令

env DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib/ ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" sudo -E pip install cffi

日志

bhushanvaiude$ env DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib/ ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" sudo -E pip install cffi
Password:
Downloading/unpacking cffi
  Downloading cffi-0.8.6.tar.gz (196kB): 196kB downloaded
  Running setup.py egg_info for package cffi
    warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]
    1 warning generated.
    
Downloading/unpacking pycparser (from cffi)
  Downloading pycparser-2.10.tar.gz (206kB): 206kB downloaded
  Running setup.py egg_info for package pycparser
    
Installing collected packages: cffi, pycparser
  Running setup.py install for cffi
    warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]
    1 warning generated.
    building '_cffi_backend' extension
    cc -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -I/usr/local/opt/openssl/include -Qunused-arguments -pipe -Wno-error=unused-command-line-argument-hard-error-in-future -DUSE__THREAD -I@@HOMEBREW_CELLAR@@/libffi/3.0.13/lib/libffi-3.0.13/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c c/_cffi_backend.c -o build/temp.macosx-10.9-intel-2.7/c/_cffi_backend.o
    warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]
    c/_cffi_backend.c:13:10: fatal error: 'ffi.h' file not found
    #include <ffi.h>
             ^
    1 warning and 1 error generated.
    error: command 'cc' failed with exit status 1
    Complete output from command /Users/****project path***/bin/python -c "import setuptools;__file__='/Users/****project path***/build/cffi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/7w/8z_mn3g120n34bv0w780gnd00000gn/T/pip-e6d6Ay-record/install-record.txt --single-version-externally-managed --install-headers /Users/****project path***/include/site/python2.7:
    warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]

1 warning generated.

running install

running build

running build_py

creating build

creating build/lib.macosx-10.9-intel-2.7

creating build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/__init__.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/api.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/backend_ctypes.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/commontypes.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/cparser.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/ffiplatform.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/gc_weakref.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/lock.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/model.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/vengine_cpy.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/vengine_gen.py -> build/lib.macosx-10.9-intel-2.7/cffi

copying cffi/verifier.py -> build/lib.macosx-10.9-intel-2.7/cffi

running build_ext

building '_cffi_backend' extension

creating build/temp.macosx-10.9-intel-2.7

creating build/temp.macosx-10.9-intel-2.7/c

cc -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -I/usr/local/opt/openssl/include -Qunused-arguments -pipe -Wno-error=unused-command-line-argument-hard-error-in-future -DUSE__THREAD -I@@HOMEBREW_CELLAR@@/libffi/3.0.13/lib/libffi-3.0.13/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c c/_cffi_backend.c -o build/temp.macosx-10.9-intel-2.7/c/_cffi_backend.o

warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]

c/_cffi_backend.c:13:10: fatal error: 'ffi.h' file not found

#include <ffi.h>

         ^

1 warning and 1 error generated.

error: command 'cc' failed with exit status 1

----------------------------------------
Cleaning up...

可能是[在OS X上使用pip安装bcrypt时出现错误:找不到ffi.h(已安装libffi)]的重复问题(https://dev59.com/mmAh5IYBdhLWcg3wDfoW) - Armin Rigo
得到了相同的错误,尝试了https://dev59.com/mmAh5IYBdhLWcg3wDfoW -> 对我没有用。 - fetzig
3个回答

31

在您的终端中尝试运行:

xcode-select --install

然后尝试重新安装该软件包。

默认情况下,XCode作为IDE进行安装,但不设置环境供命令行工具使用;例如,/usr/include文件夹将会缺失。

运行上述命令将安装运行编译所需的工具,并创建必要的符号链接。由于Python软件包使用XCode的命令行界面来编译本地代码部分,因此需要执行此步骤以安装包含本地组件的Python软件包。

每次安装/升级XCode时只需要执行一次,或者如果遇到类似错误时才需要执行。


你能解释得更详细一些吗? - Ant6n
看起来这是为使用Xcode进行开发设置命令行工具的好提示。 - cgseller
适用于我...不确定为什么这是一个要求 :) - markich
值得注意的是,每次 OS X 升级时我都会遇到这个问题。也许 Xcode 更新经常需要使用最新版本的 OS X。 - Taylor D. Edmiston
在我的 macOS 12.2.1 上这个不起作用。它显示 xcode-select: error: command line tools are already installed, use "Software Update" to install updates,之后 cffi 安装一直失败。 - ajendrex

25

1
你值得敬佩,我的朋友! - nehem
1
我首先需要运行命令 "brew unlink pkg-config",然后按照您的指示操作,现在它很好地工作了。 - aris
1
brew install pkg-config libffi 然后 pip install cffi 就足够了。谢谢! - Benjamin Castor

-3
在终端中运行以下命令解决了我的问题。
xcode-select --install

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接