I am using this example from python documentation
#include <Python.h>
int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is', ctime(time()))\n");
Py_Finalize();
return 0;
}
where python script is hard-coded to a C program. But when i try to compile it by
$ gcc -c modwithpy.c -o mod
i receive an error:
modwithpy.c:1:20: fatal error: Python.h: No such file or directory compilation terminated.
however, i have already install python-dev package. I also looked at compiling and linking documentation and don't understand what absolute path for python package i need to write.
$ whereis python
python: /usr/bin/python3.3m /usr/bin/python /usr/bin/python2.7-config
/usr/bin/python3.3 /usr/bin/python2.7 /etc/python /etc/python3.3 /etc/python2.7
/usr/lib/python2.6 /usr/lib/python3.3 /usr/lib/python2.7 /usr/bin/X11/python3.3m
/usr/bin/X11/python /usr/bin/X11/python2.7-config /usr/bin/X11/python3.3
/usr/bin/X11/python2.7 /usr/local/lib/python3.3 /usr/local/lib/python2.7
/usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
1 Answer 1
You didn't read quite far enough. The documentation here shows how to tell the compiler where python headers and libraries are located.
Based on this, try
gcc `/opt/bin/python3.3-config --cflags` modwithpy.c -o mod \
`/opt/bin/python3.3-config --ldlags`
If your python installed scripts in a different place, you will have to change the /opt/bin to the place where ...-config is really located. From your whereis trace, it could be /usr/bin.
Python.hlives, then make sure to add that path to theINCLUDEpath for your compiler. What compiler are you using?Python.hheader is found. You seem to have multiple versions around, so you need to decide which you want to link with — probably the 3.3 version. So, there is probably a/usr/bin/python3.3-config(orpython3.3m-config) file; use that. There is definitely a 2.7 config, so if you're OK with linking to Python 2.7, you can use that.