在Ubuntu上安装PyCrypto - 构建时出现致命错误

67

在查看了其他类似的线程后,我仍然无法运行pycrypto。

我正在尝试让其在我的Ubuntu笔记本电脑上运行 - 但我在我的Windows PC上也无法管理它。

我下载了pycrypto-2.6,进行了解压,并运行了:

    python setup.py build

但是随后发生了这件事情

warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Hash._MD2' extension
gcc -pthread -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -fPIC -std=c99 -O3 - fomit-frame-pointer -Isrc/ -I/usr/include/python2.7 -c src/MD2.c -o build/temp.linux-i686-?2.7/src/MD2.o
src/MD2.c:31:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

非常感谢任何帮助。


你没有Python的开发头文件。但是,如果你只需要该模块,为什么不使用easy_install或pip进行安装呢? - qrtt1
使用easy_install(没有安装python-dev包)会出现相同的错误。 - Brent Faust
使用pip(不带python-dev包)会出现相同的错误。 - OmarOthman
4个回答

154

你需要安装Python开发文件。我认为以下命令将会实现目标:

sudo apt-get install python-dev

3
在OpenSuse中,执行以下命令:'sudo zypper in python-devel' - sean_m
4
对于Python3:根据发行版选择apt-get install python3.2-devapt-get install python3.3-dev - Nirvana Tikku
2
如果您使用的是Fedora,请执行以下命令:sudo dnf install python-devel - Bruno Casali
8
针对 Python 3.6 版本,执行以下命令安装 python3.6-dev 开发包:apt-get install python3.6-dev - Berlin
1
对于任何Python 3版本:apt-get install python3-dev - Yann Dìnendal
显示剩余3条评论

22

在Ubuntu上,我需要安装其他一些软件包才能成功:

apt-get install autoconf g++ python2.7-dev
pip install pycrypto

它也适用于Ubuntu 16.04 LTS。我想知道为什么这个软件包在pypi上缺少wheel文件? - nagylzs

7

如果你使用的是Python 3.x,且在Ubuntu操作系统上,你需要:

sudo apt-get install gcc python3-dev

你可能已经安装了gcc,但是以防万一,如果你正在使用基于python:3.6.4-slim-jessie镜像的Dockerfile尝试这个命令,那么你也需要安装gcc。


1
在运行/安装sudo apt-get install python3.7之后,我实际上需要运行sudo apt-get install python3.7-dev,不确定为什么python3-dev不能通过apt-get依赖项来覆盖此操作,但它可以解决问题。 - Edward
1
@Edward,你在2021年7月的AWS CodeBuild中的评论真的帮了我很多。也许你可以把它发表为一个答案。 - Tommy

2

2021年8月

对于Python 3.8用户,请运行:

sudo apt-get install python3.8-dev

尝试重新安装pycrypto。
pip install pycrypto

最好使用“python3-dev”,它是一个元包,根据已安装的Python版本自动选择正确的软件包。 - Frank

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