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??
For me, changing it to this worked:
I found the file
/usr/include/python2.7/Python.h
, and since/usr/include
is already in the include path, thenpython2.7/Python.h
should be sufficient.You could also add the include path from command line instead -
gcc -I/usr/lib/python2.7
(thanks @erm3nda).AWS EC2 install running python34:
sudo yum install python34-devel
If you are using tox to run tests on multiple versions of Python, you may need to install the Python dev libraries for each version of Python you are testing on.
try apt-file. It is difficult to remember the package name where the missing file resides. It is generic and useful for any package files.
For example:
Now you can make an expert guess as to which one to choose from.
For the OpenSuse comrades out there:
This error occurred when I attempted to install ctds on CentOS 7 with Python3.6. I did all the tricks mentioned here including
yum install python34-devel
. The problem wasPython.h
was found in/usr/include/python3.4m but not in /usr/include/python3.6m
. I tried to use--global-option
to point to include dir (pip3.6 install --global-option=build_ext --global-option="--include-dirs=/usr/include/python3.4m" ctds
). This resulted in alpython3.6m
not found when linking ctds.Finally what worked was fixing the development environment for Python3.6 needs to correct with the include and libs.
Python.h needs to be in your include path for gcc. Whichever version of python is used, for example if it's 3.6, then it should be in
/usr/include/python3.6m/Python.h
typically.