python3 安装cffi报错

Posted 渔夫数据库笔记

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3 安装cffi报错相关的知识,希望对你有一定的参考价值。

1.操作系统版本

cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

2.问题现象

安装 fabric 报错

/usr/local/python3.5/bin/pip3  install fabric3
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Collecting fabric3
  Using cached Fabric3-1.14.post1-py3-none-any.whl (92 kB)
Requirement already satisfied: six>=1.10.0 in /usr/local/python3.5/lib/python3.5/site-packages (from fabric3) (1.16.0)
Collecting paramiko<3.0,>=2.0
  Using cached paramiko-2.12.0-py2.py3-none-any.whl (213 kB)
Collecting cryptography>=2.5
  Using cached cryptography-3.2.1-cp35-abi3-manylinux2010_x86_64.whl (2.6 MB)
Collecting pynacl>=1.0.1
  Using cached PyNaCl-1.4.0-cp35-abi3-manylinux1_x86_64.whl (961 kB)
Collecting bcrypt>=3.1.3
  Using cached bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.whl (56 kB)
Collecting cffi>=1.1
  Using cached cffi-1.15.1.tar.gz (508 kB)
Requirement already satisfied: pycparser in /usr/local/python3.5/lib/python3.5/site-packages (from cffi>=1.1->bcrypt>=3.1.3->paramiko<3.0,>=2.0->fabric3) (2.21)
Using legacy 'setup.py install' for cffi, since package 'wheel' is not installed.
Installing collected packages: cffi, pynacl, cryptography, bcrypt, paramiko, fabric3
    Running setup.py install for cffi ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/python3.5/bin/python3.5 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ag15n1af/cffi_cd2027f1e465449a88b21dc5c515517e/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ag15n1af/cffi_cd2027f1e465449a88b21dc5c515517e/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\\r\\n'"'"', '"'"'\\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-ser0p7l2/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/python3.5/include/python3.5m/cffi
         cwd: /tmp/pip-install-ag15n1af/cffi_cd2027f1e465449a88b21dc5c515517e/
    Complete output (56 lines):
    Package libffi was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libffi.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libffi' found
    Package libffi was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libffi.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libffi' found
    Package libffi was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libffi.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libffi' found
    Package libffi was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libffi.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libffi' found
    Package libffi was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libffi.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libffi' found
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    creating build/lib.linux-x86_64-3.5/cffi
    copying cffi/__init__.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/api.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/commontypes.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/cparser.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/error.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/lock.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/model.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/recompiler.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/verifier.py -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/_embedding.h -> build/lib.linux-x86_64-3.5/cffi
    copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.5/cffi
    running build_ext
    building '_cffi_backend' extension
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/c
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/python3.5/include/python3.5m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.5/c/_cffi_backend.o
    c/_cffi_backend.c:15:17: fatal error: ffi.h: No such file or directory
     #include <ffi.h>
                     ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/python3.5/bin/python3.5 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ag15n1af/cffi_cd2027f1e465449a88b21dc5c515517e/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ag15n1af/cffi_cd2027f1e465449a88b21dc5c515517e/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\\r\\n'"'"', '"'"'\\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-ser0p7l2/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/python3.5/include/python3.5m/cffi Check the logs for full command output.

3.问题原因

上述报错是因为缺少依赖包导致的,需要安装如下依赖包

1)centos 安装命令如下:

yum install -y libffi-devel

2)Ubuntu 下安装命令如下

apt install libffi-dev

4.问题处理

1)安装依赖包

yum install -y libffi-devel

2)重新安装fabric

/usr/local/python3.5/bin/pip3  install fabric
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Collecting fabric
  Using cached fabric-2.7.1-py2.py3-none-any.whl (53 kB)
Collecting invoke<2.0,>=1.3
  Using cached invoke-1.7.3-py3-none-any.whl (216 kB)
Collecting paramiko>=2.4
  Using cached paramiko-2.12.0-py2.py3-none-any.whl (213 kB)
Collecting pathlib2
  Using cached pathlib2-2.3.7.post1-py2.py3-none-any.whl (18 kB)
Collecting bcrypt>=3.1.3
  Using cached bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.whl (56 kB)
Requirement already satisfied: six in /usr/local/python3.5/lib/python3.5/site-packages (from paramiko>=2.4->fabric) (1.16.0)
Collecting pynacl>=1.0.1
  Using cached PyNaCl-1.4.0-cp35-abi3-manylinux1_x86_64.whl (961 kB)
Collecting cryptography>=2.5
  Using cached cryptography-3.2.1-cp35-abi3-manylinux2010_x86_64.whl (2.6 MB)
Collecting cffi>=1.1
  Using cached cffi-1.15.1.tar.gz (508 kB)
Requirement already satisfied: pycparser in /usr/local/python3.5/lib/python3.5/site-packages (from cffi>=1.1->bcrypt>=3.1.3->paramiko>=2.4->fabric) (2.21)
Using legacy 'setup.py install' for cffi, since package 'wheel' is not installed.
Installing collected packages: cffi, pynacl, cryptography, bcrypt, pathlib2, paramiko, invoke, fabric
    Running setup.py install for cffi ... done
Successfully installed bcrypt-3.1.7 cffi-1.15.1 cryptography-3.2.1 fabric-2.7.1 invoke-1.7.3 paramiko-2.12.0 pathlib2-2.3.7.post1 pynacl-1.4.0

以上是关于python3 安装cffi报错的主要内容,如果未能解决你的问题,请参考以下文章

python3 安装cffi报错

加载 dll 时 Python CFFI 模块失败:OSError 0x7e

使用 ctypes/cffi 解决循环共享对象依赖关系

python3之scrapy安装使用

在 Windows 上安装 python 库 cffi

c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory