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.

3
  • You have no developing header for python. However, if you just need the module why don' you install by easy_install or pip ?
    – qrtt1
    Jul 22, 2012 at 0:23
  • Same error using easy_install (without the python-dev package). Aug 9, 2014 at 7:21
  • Same error using pip (without the python-dev package).
    – OmarOthman
    Sep 15, 2017 at 11:12

4 Answers 4

154

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

sudo apt-get install python-dev
8
  • 3
    'sudo zypper in python-devel' for OpenSuse
    – sean_m
    Jun 1, 2013 at 2:09
  • 4
    For Python3: apt-get install python3.2-dev or apt-get install python3.3-dev, depending on distro Apr 24, 2015 at 23:32
  • 2
    sudo dnf install python-devel if you are in Fedora. Dec 3, 2015 at 2:48
  • 8
    for python 3.6: apt-get install python3.6-dev
    – Berlin
    Apr 16, 2017 at 7:07
  • 1
    for any python 3 version: apt-get install python3-dev Dec 19, 2018 at 16:30
22

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

apt-get install autoconf g++ python2.7-dev
pip install pycrypto
1
  • It also works on Ubuntu 16.04 LTS. I wonder why the wheel is missing from pypi for this package?
    – nagylzs
    Feb 27, 2017 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.

2
  • 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 4, 2019 at 11:04
  • 1
    @Edward your comment just saved me in AWS CodeBuild in July 2021.. possibly post it as an answer.
    – Tommy
    Jul 8, 2021 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
1
  • 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, 2022 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.