Cython+NumPy - compiler not using numpy.pyd
Question: I have a code that uses numpy and I want to compile it using Cython. I added
the cimport directive:

    
    
    import numpy as np
    cimport numpy as np
    

I am on Windows 7, compiling using distutils with gcc (MinGW) as the compiler.
It yields an error when I try to compile it. This is the error:

    
    
    ssepMC.c:346:31: fatal error: numpy/arrayobject.h: No such file or directory
     #include "numpy/arrayobject.h"
                                   ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    

I believe this error occurs because the compiler is trying to compile the
numpy package. But this is an unnecessary step because a compiled version of
numpy exists in Cython under

    
    
    C:\Python27\Lib\site-packages\Cython\Includes\numpy\numpy.pxd
    

So the question is: How do I make the compiler use the compiled version of
numpy?

Thanks in advance.


Answer: As mentioned elsewhere, you need to point `gcc` to `numpy/arrayobject.h` which
you can do by setting `include_dirs` to `[np.get_include()]`.

Note - this is not 'recompiling' numpy, this is using the directives in the
numpy arrayheader file to instruct `gcc` how to compile your code.

    
    
    from Cython.Build import cythonize
    import numpy as np
    
    ext_modules = [Extension("hello", ["hello.pyx"], include_dirs=[np.get_include()])]
    
    setup(
      ext_modules = cythonize(extensions)
    )
    

