The answer is on the docs of cryptography‘s installation section which pretty much reflects Angelos’ answer:
Quoting it:
For Debian and Ubuntu, the following command will ensure that the
required dependencies are installed:$ sudo apt-get install build-essential libssl-dev libffi-dev python-devFor Fedora and RHEL-derivatives, the following command will ensure
that the required dependencies are installed:$ sudo yum install gcc libffi-devel python-devel openssl-develYou should now be able to build and install cryptography with the
usual$ pip install cryptography
If you’re using Python 3, please use python3-dev instead of python-dev in the first command. (thanks to @chasmani)
If you’re installing this on Ubuntu 18.04, please use libssl1.0 instead of libssl-dev in the first command. (thanks to @pobe)