It turns out that this is no longer the case. With setuptools and distutils (at least the numpy version) it is possible to have extensions with C, Cython, and f2py. The only caveat is that you must always use numpy.distutils for the setup and Extension functions to compile f2py modules. But setuptools can still be used for installation (for example, allowing the installation of a developer version with python setup.py develop ).
To use distutils exclusively, you use the following:
from numpy.distutils.core import setup from numpy.distutils.extension import Extension
To use setuptools , you need to import it before importing distutils :
import setuptools
And then the rest of the code is identical:
from numpy import get_include from Cython.Build import cythonize NAME = 'my_package' NUMPY_INC = get_include() extensions = [ Extension(name=NAME + ".my_cython_ext", include_dirs=[NUMPY_INC, "my_c_dir"] sources=["my_cython_ext.pyx", "my_c_dir/my_ext_c_file.c"]), Extension(name=NAME + ".my_f2py_ext", sources=["my_f2py_ext.f"]), ] extensions = cythonize(extensions) setup(..., ext_modules=extensions)
Obviously, you need to put all other things in the setup() call. In the above example, I assume that you will use numpy with Cython along with the external C file ( my_ext_c_file.c ), which will be in my_c_dir/ , and that the f2py module is only one Fortran file. Adjust if necessary.
tiago Jan 27 '17 at 14:21 2017-01-27 14:21
source share