Compile Fortran module with f2py

You are trying to have a Fortran module in a Python module. If you want that, the names must be different, e.g.

 f2py.py -c -m SOMEDIFFERENTNAME itimes-s2.f

The result will be called as pythonmodule.fortranmodule.yourfunction().

You can also import it as

from pythonmodule import fortranmodule
fortranmodule.yourfunction()

Otherwise it worked on my machine.


For f2py to work you need to have a signature file to direct the interface creation or modify your source code with f2py comments to help with the interface. See http://cens.ioc.ee/projects/f2py2e/usersguide/#signature-file for more information.

From that site:

C FILE: FIB3.F
      SUBROUTINE FIB(A,N)
C
C     CALCULATE FIRST N FIBONACCI NUMBERS
C
      INTEGER N
      REAL*8 A(N)
Cf2py intent(in) n
Cf2py intent(out) a
Cf2py depend(n) a
      DO I=1,N
         IF (I.EQ.1) THEN
            A(I) = 0.0D0
         ELSEIF (I.EQ.2) THEN
            A(I) = 1.0D0
         ELSE 
            A(I) = A(I-1) + A(I-2)
         ENDIF
      ENDDO
      END
C END FILE FIB3.F

Building the extension module can be now carried out in one command:

f2py -c -m fib3 fib3.f