3

I have a python package "trees", which contains myscript.py file which makes use of a fortran subroutine.

Normally I compile the fortran module with

f2py -c -m calctree calctree.f90

and I can then do

from trees import myscript
myscript.mysub()

which makes use of calctree.so

If I package everything with distutils by running

python ./setup.py sdist

where the contents of setup.py are

#! /usr/bin/env python
from distutils.core import setup

setup(name='trees',
      version='0.1',
    packages=['trees']
    )

and specify "include trees/calctree.f90" in a MANIFEST.in file, I can include the .f90 file, but I don't know how to make it compile with f2py on the user's computer, and have the .so file placed in an appropriate place. Can anybody help?

Thank you!

Tetsuo
  • 169
  • 1
  • 2
  • 9
  • No idea about a built-in solution, but you could just run the command yourself in the module before calling `setup` and then include the compiled file in the setup call. – Voo Jan 22 '13 at 07:07

1 Answers1

1

You want to use the numpy.distutils.core module which has its own setup function. Your setup.py should look something like this (assuming the fortran files are in the directory named trees),

import numpy.distutils.core
import setuptools


# setup fortran 90 extension
#---------------------------------------------------------------------------  
ext1 = numpy.distutils.core.Extension(
    name = 'calctree',
    sources = ['trees/calc_tree.f90'],
    )


# call setup
#--------------------------------------------------------------------------
numpy.distutils.core.setup( 

    name = 'trees',
    version = '0.1',        
    packages = setuptools.find_packages(), 
    package_data = {'': ['*.f90']}, 
    include_package_data = True,   
    ext_modules = [ext1],

)  

That should be a start at least.