No subject


Thu Jun 29 10:37:20 CDT 2006


def psmtestfunc(a):
    a = a * 0.4534534e-13
    return a

> ________________________________________________________________________
> 
> 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

Use f2py to build the extension module as follows:

  f2py -c psmtest.pyf psmtest.c

This should create perrin.so into the current directory. Now run python
and try the following session:

>>> import perrin
>>> perrin.psmtestfunc([1,2,3,4])
array([  4.53453400e-14,   9.06906800e-14, 1.36036020e-13,  1.81381360e-13])
>>> print perrin.psmtestfunc.__doc__

> 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.

f2py provides array_from_pyobj that is in f2py2e/src/fortranobject.c.
However, if you use `f2py -c' to build extension modules then f2py does
the "right" thing automatically.

Regards,
	Pearu




More information about the SciPy-user mailing list