I have installed libffi on my Linux server as well as correctly set the PKG_CONFIG_PATH environment variable to the correct directory, as pip
libffi
PKG_CONFIG_PATH
pip
You can use CFLAGS (and LDFLAGS or various other compiler and linker options) in front of the pip command (ditto for setup.py):
CFLAGS
LDFLAGS
setup.py
Something similar to the following should work:
CFLAGS=-I/usr/include/libffi/include pip install pyOpenSSL