[Numpy-discussion] how to compile Fortran using setup.py

Robert Kern robert.kern at gmail.com
Thu Mar 10 23:25:14 EST 2011


On Thu, Mar 10, 2011 at 19:58, Ondrej Certik <ondrej at certik.cz> wrote:
> Hi,
>
> I spent about an hour googling and didn't figure this out. Here is my setup.py:
>
> setup(
>    name = "libqsnake",
>    cmdclass = {'build_ext': build_ext},
>    version = "0.1",
>    packages = [
>        'qsnake',
>        'qsnake.calculators',
>        'qsnake.calculators.tests',
>        'qsnake.data',
>        'qsnake.mesh2d',
>        'qsnake.tests',
>        ],
>    package_data = {
>        'qsnake.tests': ['phaml_data/domain.*'],
>        },
>    include_dirs=[numpy.get_include()],
>    ext_modules = [Extension("qsnake.cmesh", [
>        "qsnake/cmesh.pyx",
>        "qsnake/fmesh.f90",
>        ])],
>    description = "Qsnake standard library",
>    license = "BSD",
> )
>
> The qsnake.cmesh extension needs to compile .pyx into .c and later to
> .o, it needs to use gfortran to compile fmesh.f90 to fmesh.o, and then
> link both things. That's it. In other words, this is what I want
> distutils to do:
>
> $ cython cmesh.pyx
> $ gcc -fPIC -o cmesh.o -c cmesh.c -I$SPKG_LOCAL/include/python2.6
> -I$SPKG_LOCAL/lib/python2.6/site-packages/numpy/core/include
> $ gfortran -fPIC -o fmesh.o -c fmesh.f90
> $ gcc -shared -o cmesh.so cmesh.o fmesh.o

Difficult if sticking with distutils of any flavor. You would have
probably to replace the build_ext command to handle both the Fortran
and the Cython. You may want to give David Cournapeau's Bento a try:

  http://pypi.python.org/pypi/bento/

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list