Last week, I had an error when installing cryptography by pip. Then I did a lot of searches, and most of the answers told me to install python-devel, but it still didn't work after I installed that, which drove me crazy. By the way, my process was running on Centos 7.4, and my python version is 2.7.5.

While installing cryptography by pip, GCC needs to compile a bunch of C files, and the C files reference header files, such as <pyconfig.h>. However, the GCC did not search pyconfig.h in /usr/include/python2.7/, because the GCC default search path does not include that path. We can print the current search pathes of GCC via command: gcc -xc -E -v -.

Finally, after I found the radical problem of this error, it was easy to solve by including a new search path for the GCC. Here is the command: export C_INCLUDE_PATH="$C_INCLUDE_PATH:/usr/include/python2.7/"