I have Python on my Ubuntu system, but gcc can't find Python.h

user979344 picture user979344 · Nov 26, 2011 · Viewed 110.5k times · Source

I am on a school computer, so I can't install anything.

I am trying to create C code which can be run in Python. It seems all the articles I am finding on it require you to use

#include <Python.h>

I do this, but when I compile it complains that there is no such file or directory.

The computer has Python (at least it has the python command in the terminal, and we can run whatever Python code we want).

I typed in locate Python.h in the terminal, but it found nothing.

I have two questions:

  1. Can I write C code that I can call in Python without Python.h?

  2. Am I missing something, and the computer actually has Python.h?

Answer

Andrew Marsh picture Andrew Marsh · Nov 26, 2011

You need the python-dev package which contains Python.h