Question

So I've got a directory that looks something like this:

 home\
     setup.py
     some_python_file.py
     ext\
         __init__.py
         c_file1.c
         c_file2.c
         ext_header.h

Obviously the header file is necessary to compile the c files, but the problem is that I can't get the setup script to include the header file.

My extension object is something like this:

Extension('ext.the_extension', ['ext/c_file1.c', 'ext/c_file2.c'])

Which works, but doesn't include the header file. If I change it to:

Extension('ext.the_extension', ['ext/c_file1.c', 'ext/c_file2.c', 'ext_header.h'])

It includes the '.h' file but then doesn't build when I run install. Instead it gives and error error: unknown file type '.h' (from 'ext/ext_header.h')

If I include the header file as a data file like this:

data_files=[('ext', ['ext/ext_header.h'])]

it doesn't work at all, the .h file doesn't even make it into the MANIFEST file.

So my queustion is, how do you include this extension with the header file so that python setup.py install will build it correctly?

Was it helpful?

Solution

I have a feeling pyfunc is on track for a more standard solution, but I did find another solution on my own. I have no idea if this is a good solution or just a hack, but all I did is add the header file to the MANIFEST.in. The documentation doesn't really make it seem like this is what the MANIFEST.in file is for, but it does work. My MANIFEST.in file now looks like this:

include ext/ext_header.h

Which includes the file and sucessfully compiles when I run python setup.py install

OTHER TIPS

From the docs,

module1 = Extension('demo',
                define_macros = [('MAJOR_VERSION', '1'),
                                 ('MINOR_VERSION', '0')],
                include_dirs = ['/usr/local/include'],
                libraries = ['tcl83'],
                library_dirs = ['/usr/local/lib'],
                sources = ['demo.c'])

You should provide the include files via "include_dirs".

Why does this not work for you?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top