I am trying to build a shared library using a C extension file but first I have to generate the output file using the command below:
gcc -Wall utilsmodule.c -o Utilc
After executing the command, I get this error message:
utilsmodule.c:1:20: fatal error: Python.h: No such file or directory compilation terminated.
in fact I have tried all the suggested solutions over the internet but the problem still exists ... also I have no problem with Python.h
. I managed to locate the file on my machine ... anybody has faced the same problem before??
In my case, what fixed it in Ubuntu was to install the packages
libpython-all-dev
(orlibpython3-all-dev
if you use Python 3).Make sure that the Python dev files come with your OS.
You should not hard code the library and include paths. Instead, use pkg-config, which will output the correct options for your specific system:
You may add it to your gcc line:
If you use a virtualenv with a 3.6 python (edge right now), be sure to install the matching python 3.6 dev
sudo apt-get install python3.6-dev
, otherwise executingsudo python3-dev
will install the python dev 3.3.3-1, which won't solve the issue.If you are using a Raspberry Pi:
Sure
python-dev
orlibpython-all-dev
are the first thing to (apt
)install
, but if that doesn't help as was my case, I advice you to install the foreign Function Interface packages bysudo apt-get install libffi-dev
andsudo pip install cffi
.This should help out especially if you see the error as/from
c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory
.Sometimes even after installing python-dev the error persists, Check for the error if it is 'gcc' missing.
First download as stated in https://stackoverflow.com/a/21530768/8687063, then install gcc
For apt (Ubuntu, Debian...):
For yum (CentOS, RHEL...):
For dnf (Fedora...):
For zypper (openSUSE...):
For apk (Alpine...):