3

I am trying to compile a minimal Fortran90 subroutine with f2py, to use with Python 3. It is working when I use Python 2.7, but when to import it in a Python 3 file, I get an error message. I need it to work in Python 3.

My Fortran subroutine:

subroutine test(a,b)
    implicit none

    integer, intent(in) :: a
    integer, intent(out) :: b

    b = a*2
end subroutine

This is how I compile:

f2py -c test.f90 -m test 

Then I try to import in Python 3 like so

import test

and get this error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /home/.../hello.so: undefined symbol: PyCObject_Type

I have searched for this error, but found nothing that makes sense to me.

  • 2
    You did download and install the Python 3 version of the module, did you? – cdarke Mar 16 '15 at 15:33
  • As far as I understand, numpy comes with f2py. I checked the Numpy version in Python3 and it is version 1.9.2. Should I install a different version of f2py? –  Mar 16 '15 at 15:42
  • 1
    It could just be that you are picking-up the wrong version on the command-line. Check with `which f2py` or similar. – cdarke Mar 16 '15 at 15:48
  • I was indeed using a wrong version. I now compiled with f2py3 and now it works . Thank you very much. –  Mar 16 '15 at 16:01

1 Answers1

3

As @cdarke pointed out, I was using a wrong version of f2py. Compiling with f2py3.4 fixed the problem.