Python安装cryptography时出现报错的解决方法

2023-05-20,,

本篇文章给大家分享的是有关Python安装cryptography时出现报错的解决方法,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

错误一:

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python2.7 -c c/_cffi_backend.c -o build/temp.linux-x86_64-2.7/c/_cffi_backend.o

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

compilation terminated.

error: command 'gcc' failed with exit status 1

原因:

缺少头文件和静态库包

解决方法:

sudo apt-get install libffi-dev

错误二:

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c build/temp.linux-x86_64-2.7/_openssl.c -o build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o -Wconversion -Wno-error=sign-conversion

build/temp.linux-x86_64-2.7/_openssl.c:28:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

原因:

缺少Python的头文件和静态库包

解决方法:

sudo apt-get install python-dev

补充知识:windows 中 pip 安装库时出现 cryptography 报错 解决方案

如果在安装程序中,系统提示有cryptography 的报错,并提示有类似C:\Users\Administrator\AppData\Roaming\pip

这种路径提示信息,那么是你的 pip 源出现了问题。

首先,打开该路径文件。一般这种文件的类型是隐藏文件,在win10的页面工具栏中有相应的显示文件的选项,

而在win7中在工具——文件夹选项中。之后输入你的 pip 路径例如:C:\Users\Administrator\AppData\Roaming\pip

最后,打开 pip.ini 文件 在里面写入

[global]

timeout = 6000

index-url = https://pypi.mirrors.ustc.edu.cn/simple

trusted-host = pip.mirrors.ustc.edu.cn

不行的话,试试更新pip,在执行上面步骤。

以上就是Python安装cryptography时出现报错的解决方法,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注本站行业资讯频道。

《Python安装cryptography时出现报错的解决方法.doc》

下载本文的Word格式文档,以方便收藏与打印。