I have recently worked on a project that used Python 3 and Flask – a Python micro-framework and while deploying the application into staging, one of the errors that I have encountered was installing flask-bcrypt extension which get stuck when installing bcrypt and cffi (c foreign function interface). The server is running Ubuntu Linux 14.04 Trusty LTS and Python 3.
Downloading/unpacking pycparser (from cffi>=1.1->bcrypt->flask-bcrypt)
Downloading pycparser-2.16.tar.gz (230kB): 230kB downloaded
Running setup.py (path:/tmp/pip_build_root/pycparser/setup.py) egg_info for package pycparser
warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
warning: no previously-included files matching 'lextab.*' found under directory 'tests'
warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
warning: no previously-included files matching 'lextab.*' found under directory 'examples'
Installing collected packages: flask-bcrypt, bcrypt, cffi, pycparser
Running setup.py install for flask-bcrypt
Running setup.py install for bcrypt
c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory
#include <python .h>
Anyway, here’s how to fix the above error.
1. Make sure to update your repository list to latest
sudo apt-get update
2. When update is finished, install the following packages, python-dev if you are using python2
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
3. Install flask-bcrypt
sudo pip3 install flask-bcrypt
That’s it, you should have flask-bcrypt extension installed already. To use flask-bcrypt, follow this link for usage documentation.