[Fixed] installing Python cryptography package error "ffi.h: No such file or directory"

When installing Scrapy, it'll install Python cryptography package, but getting the following error:

raise DistutilsError("Setup script exited with %s" % (v.args[0],))    distutils.errors.DistutilsError: Setup script exited with error: command 'i686-linux-gnu-gcc' failed with exit status 1    Complete output from command /home/ubuntu/.virtual_envs/env/bin/python -c "import setuptools, tokenize;__file__='/home/ubuntu/.virtual_envs/env/build/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-SVMn92-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ubuntu/.virtual_envs/env/include/site/python2.7:    c/_cffi_backend.c:13:17: fatal error: ffi.h: No such file or directory
 #include
                 ^
compilation terminated....distutils.errors.DistutilsError: Setup script exited with error: command 'i686-linux-gnu-gcc' failed with exit status 1


How to fix this error?

For Debian or Ubuntu, install required dependencies by using the following command:
$ sudo apt-get install build-essential libssl-dev libffi-dev python-dev
For Fedora:
$ sudo yum install gcc libffi-devel python-devel openssl-devel
And install cryptography:
$ pip install cryptography
It works.

Comments

simfront said…
It’s really nice and meaningful. It’s really cool blog. You have really helped lots of people who visit Blog and provide them useful information. Thanks for sharing. FFI