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??
It's not the same situation, but it also works for me and now I can use SWIG with Python3.5:
I was trying to compile:
With Python 2.7 works fine, not with my version 3.5:
After run in my Ubuntu 16.04 installation:
Now I can compile without problems Python3.5:
I would like to add also the solution for Cygwin:
You need to install the package
python2-devel
orpython3-devel
, depending on the Python version you're using.You can quickly install it using the 32-bit or 64-bit
setup.exe
(depending on your installation) from Cygwin.com.Example (modify
setup.exe
's filename and Python's major version if you need):You can also check my other answer for a few more options to install Cygwin's packages from the command-line.
Two things you have to do.
Install development package for Python, in case of Debian/Ubuntu/Mint it's done with command:
Second thing is that include files are not by default in the include path, nor is Python library linked with executable by default. You need to add these flags (replace Python's version accordingly):
In other words your compile command ought to be:
I managed to solve this issue and generate the .so file in one command
I also encountered this error when I was installing coolprop in ubuntu.
For ubuntu 16.04 with python 3.6
If ever this doesn't work try installing/updating
gcc
lib.This means that
Python.h
isn't in your compiler's default include paths. Have you installed it system-wide or locally? What's your OS?You could use the
-I<path>
flag to specify an additional directory where your compiler should look for headers. You will probably have to follow up with-L<path>
so that gcc can find the library you'll be linking with using-l<name>
.