[Distutils] How to add include dirs for compiler

Greg Ward gward@python.net
Fri Sep 22 22:04:01 2000

On 22 September 2000, Dragons Spam Account said:
> How do I inform distutils of addition include directories to find headers in
> when compiling c source in a python module.

Use the --include (-I) option to "build_ext".

> I installed one module that provides a header file.
> Rather than inflict my additions on all the users of the system
> I'm installing locally to my own home directory with --home=~

OK, sounds straightforward so far.

> This pops the libraries and such into ~/lib/python but drops the header
> file into ~/include python. 

Yup, all working as planned.

> Now I attempt to install a second seperate module that relies
> on the first module. Regardless of whether I install this second
> module to the system or just to my home directory it needs to
> find that header and I can't seem to find the interface through
> which to provide distutils with additional include directories
> to use when compiling source. Which in this case would be ~/include/python.

D'ohh!  Well, Distutils really can't figure this out automatically: it
can only presume that what it needs is installed to the standard Python
directories, and if you put stuff elsewhere, you'll have to tell it.
Luckily, this isn't hard.  Instead of running just

    python setup.py build

you would tack on some "build_ext" options to control how extensions are 

    python setup.py build build_ext -n -I/your/home/dir/include/python

Note that you can't use ~ here; only the "install" command expands ~ and