[SciPy-user] problem with getting F2Py to work

Perrin Meyer perrin at MSLI.com
Tue Sep 10 14:22:55 EDT 2002


Hi.

I recently attended the Scientific Python conference at CalTech, and
there I was told about the F2Py package for wrapping numerical
C/Fortran code for use in Python.

I'm having a little trouble getting it working.

I'm trying to wrap the simple C function psmtest.c:

extern void psmtestfunc(double * A,int *m) {
  int i;
  for (i=0 ; i < *m ; i++) {
    A[i] = A[i] * 0.4534534e-13;
  }
}

I use the Fortran 90 Signature file psmtest.pyf:

python module perrin
  interface
     subroutine psmtestfunc(A,m)
       integer m
       real*8 A(m)
     end subroutine psmtestfunc
  end interface
end module perrin
________________________________________________________________________

which creates the perrinmodule.c file (attached).

I compile with:

gcc -shared -o perrinmodule.so -I 
/home/perrin/PYTHON_INSTALL/include/python2.2/ -I 
/home/perrin/PYTHON_INSTALL/lib/python2.2/site-packages/f2py2e/src/  \
-L /home/perrin/PYTHON_INSTALL/lib/python2.2/site-packages/Numeric  
psmtest.c perrinmodule.c

to create the file perrinmodule.so

When I try to import the module into Python, I get the following error 
message:

[perrin at wave PSM_TEST]$ psmpython
Python 2.2.1 (#1, Aug 23 2002, 12:31:50)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from Numeric import *
 >>> import Numeric
 >>> from perrin import *
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: ./perrinmodule.so: undefined symbol: array_from_pyobj
 >>>

I guess I'm probably linking wrong? I don't know much about creating 
shared object libraries.

Once I get it working, F2Py looks like it will be a very powerful 
package for including C code in python.

Sincerely,

Perrin Meyer


-- 
Perrin Meyer      Computational Acoustics      http://www.meyersound.com


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: perrinmodule.c
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20020910/39e0047d/attachment.c>


More information about the SciPy-User mailing list