[Numpy-discussion] cython and f2py

Keith Goodman kwgoodman at gmail.com
Fri Jul 2 16:00:51 EDT 2010


On Fri, Jul 2, 2010 at 12:53 PM, Geoffrey Ely <gely at usc.edu> wrote:
> Hi All,
>
> Sorry if this has been documented or discussed already, but my searches have come up short. Can someone please recommend a way to setup both Cython and Fortran extensions in a single package with numpy.distutils (or something else)? E.g.:
>
> from numpy.distutils.core import setup, Extension
> ext_modules = [
>    Extension( 'cext', ['cext.pyx'] ),
>    Extension( 'fext', ['fext.f90'] ),
> ]
> setup(
>    name = 'test',
>    ext_modules = ext_modules,
> )
>
> Can numpy.distutils be directed to process *.pyx with Cython rather than Pyrex?
>
> Is is kosher to call setup twice in the same script, once for Fortran, and once for Cython using Cython.Distutils.build_ext, or would that do bad things?
>
> I guess I could just pre-process the Cython stuff, and have distutils work with the generated C, but I don't like that as much.

That's what I do. I think it is easier for users (some might not have
cython). If the C extension doesn't compile I fallback to the python
versions of the functions.

http://github.com/kwgoodman/la/blob/master/setup.py



More information about the NumPy-Discussion mailing list