1

I work on a u 18.04 and a third party tool (pymesh) that I use needs to include Python.h

I installed python-dev, python3-dev, libpython-dev and libpython3-dev.

Python.h is found in the folders: /usr/include/Python/, /usr/include/Python3.6m/ and /usr/include/Python3.6/.

Still when I try to compile a minimal C-program:

#include<Python.h>
int main(){}

I get the error:

$ gcc test.c 
test.c:1:9: fatal error: Python.h: No such file or directory
 #include<Python.h>
         ^~~~~~~~~~
compilation terminated.

I can fix this by making symbolic links to every header in one of those directories in, e.g., /usr/local/include/ or by specifying the path in the #include statement, but is that the correct way of doing it?

2
  • try #include <Python/Python.h> similar to how you would #include <alsa/asoundlib.h> it's fine Commented Jun 4, 2018 at 19:55
  • Are you trying to compile pymesh or a custom program? Commented Jun 4, 2018 at 20:13

1 Answer 1

1

You should use the -I option of gcc:

gcc -I /usr/local/include test.c
Sign up to request clarification or add additional context in comments.

3 Comments

@steffen are you sure the 3rd part package doesn't have a method of re-generating the makefile (eg. cmake, automake, etc). It's pretty rare for projects to write makefiles without generation.
Do you have a config script where the location of python.h could be specified as an option?
Yep, regenerating the makefile is the way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.