67

Having looked at other similar threads, I still can't get pycrypto running.

I'm trying to get it working on my Ubuntu laptop - but I couldn't manage it on my Windows PC either.

I downloaded pycrypto-2.6, extracted it, and ran

    python setup.py build

but then this happened

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

Would appreciate any help.

OJFord
  • 10,522
  • 8
  • 64
  • 98

4 Answers4

154

You need to install the Python development files. I believe this will do it:

sudo apt-get install python-dev
Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
22

On Ubuntu, I needed some other packages for it to succeed:

apt-get install autoconf g++ python2.7-dev
pip install pycrypto
Homer6
  • 15,034
  • 11
  • 61
  • 81
  • It also works on Ubuntu 16.04 LTS. I wonder why the wheel is missing from pypi for this package? – nagylzs Feb 27 '17 at 13:31
7

On Ubuntu and if you use Python 3.x you will need:

sudo apt-get install gcc python3-dev

you probably already have gcc but just in case if you are trying this command from Dockerfile with base image python:3.6.4-slim-jessie then you will also need gcc.

Luka Lopusina
  • 2,557
  • 3
  • 27
  • 32
  • 1
    i actually needed to run `sudo apt-get install python3.7-dev` after running/installing `sudo apt-get install python3.7` not sure why `python3-dev` doesn't cover this via apt-get dependencies, but it works. – Edward Oct 04 '19 at 11:04
  • 1
    @Edward your comment just saved me in AWS CodeBuild in July 2021.. possibly post it as an answer. – Tommy Jul 08 '21 at 21:33
2

August 2021

For python 3.8 users run

sudo apt-get install python3.8-dev

and try to install pycrypto again

pip install pycrypto
  • It's better to use "python3-dev", which is a meta package that will automatically choose the correct package based on the installed python version. – Frank Mar 23 '22 at 06:52