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

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


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


On Ubuntu, you would need to install a package called python-dev. Since this package doesn't seem to be installed (locate Python.h didn't find anything) and you can't install it system-wide yourself, we need a different solution.

You can install Python in your home directory -- you don't need any special permissions to do this. If you are allowed to use a web browser and run a gcc, this should work for you. To this end

  1. Download the source tarball.

  2. Unzip with

    tar xjf Python-2.7.2.tar.bz2
  3. Build and install with

    cd Python-2.7.2./configure --prefix=/home/username/python --enable-unicode=ucs4makemake install

Now, you have a complete Python installation in your home directory. Pass -I /home/username/python/include to gcc when compiling to make it aware of Python.h. Pass -L /home/username/python/lib and -lpython2.7 when linking.


You have to use #include "python2.7/Python.h" instead of #include "Python.h".