[Distutils] NumPy extensions and setup_requires

Michael Hoffman b3i4old02 at sneakemail.com
Thu Sep 13 11:30:45 CEST 2007


I'm creating a package that uses NumPy to build an extension module. In 
order to do this, one must call numpy.get_include() like this:

ext_modules = [Extension("_fwd_bwd",
                          ["src/_fwd_bwd.pyx", "src/fwd_bwd.c"],
                          include_dirs=[numpy.get_include()])]

The problem is that if NumPy is not already installed, this will fail. I 
can't use setup_requires in a simple manner because the function call 
needs to happen before the call to setup().

The solution of creating another Distribution object to satisfy 
setup_requires before running setup() suggested in 
<http://mail.python.org/pipermail/distutils-sig/2006-October/006744.html> 
is unsatisfactory for the reasons also suggested there--if I do this 
--help will not work and it also seems a bit clunky.

I was thinking of instead making a subclass of Extension that will call 
populate include_dirs from a function rather than a list of strings. Is 
this the best solution?
-- 
Michael



More information about the Distutils-SIG mailing list