I am trying to compile c from python.

There shows the following errors after I executing the following commands:

-Wall -I/usr/include/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5m.a -lpython35 -o prime_numbers_2 prime_numbers_2.c

prime_numbers_2.c:11:20: fatal error: Python.h: No Such File or
directory compilation terminated.

I also search in the directory /usr/lib with the following command:

find . -name Python.h

but there is no Python.h in that directory.

How can I fix these problems? Should I reinstall Python3.5.2?


You should install the development package of Python which contains header files and the library of Python.

sudo apt-get install python3-dev


| improve this answer | |
  • I remove and reinstall python3-dev and check the compile links, there still shows some errors below. – PaulTsai Aug 31 '16 at 12:33
  • paultsai@paultsai-virtual-machine:~/cython/ex2$ gcc -Wall -I/usr/include/python3.5/ -lpython3.5 -L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/ -o prime_numbers_2 prime_numbers_2.c – PaulTsai Aug 31 '16 at 12:41
  • /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: in function _start: (.text+0x20): undefined reference to「main」 /tmp/ccgBhADM.o: in function __Pyx_PyObject_GetAttrStr: prime_numbers_2.c:(.text+0x61): undefined reference to「PyObject_GetAttr」 /tmp/ccgBhADM.o: in function __pyx_pf_15prime_numbers_2_is_prime: prime_numbers_2.c:(.text+0xf2): undefined reference to「PyTuple_New」 prime_numbers_2.c:(.text+0x24b): undefined reference to「PyList_Type」 prime_numbers_2.c:(.text+0x267): undefined reference to「PyTuple_Type」 – PaulTsai Aug 31 '16 at 12:42
  • There can be a problem with locations of the files mentioned in -l and -L options. Check if they exist and that -l points to a regular file and -L to a directory. – Melebius Aug 31 '16 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.