[f2py] ImportError when importing object created by F2PY, and bug report

powrsurg at gmail.com powrsurg at gmail.com
Mon Nov 7 18:44:50 EET 2005


Issuing that command alone would not let my program compile on Debian
with f2py 2.45.241_1926, python 2.3.5 (not sure which fortran compiler
is being used. I believe g77). If it helps, I am using GCC 3.3.5.

When I included

--f77flags="-O3 -fno-automatic -ffixed-line-length-none"

the program compiled, but still had the ImportError.

On 11/7/05, labrach at free.fr <labrach at free.fr> wrote:
> For me it works when settings maxn to the integer value.
> Here after the traces of
>  f2py -c au_pen.f -m mfold
> on Solaris with forte 6.2 and f2py 2.32.225-1419 and python 2.2.2)
> Hope this will help ...
>
>
>
>
> f2py -c au_pen.f -m mfold
> running build
> running run_f2py
> using F2PY 2.32.225-1419
> f2py au_pen.f -m mfold -h /tmp/@8131.0/mfold.pyf --overwrite-signature
> Reading fortran codes...
>        Reading file 'au_pen.f'
>        Reading file 'rna.inc'
>        Reading file 'maxn.inc'
> Post-processing...
>        Block: mfold
>                        Block: au_pen
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'maxn' in '2*maxn' (dimension of 'force') with '
> 8000'
> analyzevars: character rank-1 array "character seq(200000)" is considered as "ch
> aracter seq*(200000)"
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'maxn' in '-1:maxn' (dimension of 'w5') with '80
> 00'
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'maxn' in 'maxn+2' (dimension of 'w3') with '800
> 0'
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'sortmax' in 'sortmax+1' (dimension of 'heapj')
> with '90000'
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'sortmax' in 'sortmax+1' (dimension of 'heapi')
> with '90000'
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'maxn' in '2*maxn' (dimension of 'work') with '8
> 000'
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'maxn' in '2*maxn' (dimension of 'numseq') with
> '8000'
> analyzevars: character rank-1 array "character aux(8000)" is considered as "char
> acter aux*(8000)"
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'maxn' in '2*maxn' (dimension of 'hstnum') with
> '8000'
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'maxn' in '2*maxn' (dimension of 'wmb') with '80
> 00'
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'maxn' in '2*maxn' (dimension of 'strand') with
> '8000'
> In: :mfold:au_pen.f:au_pen
> analyzevars:replacing parameter 'mxbits' in '2*mxbits' (dimension of 'force2') w
> ith '2133600'
> Saving signatures to file "/tmp/@8131.0/mfold.pyf"
> f2py --build-dir /tmp/@8131.0 /tmp/@8131.0/mfold.pyf
> Reading fortran codes...
>        Reading file '/tmp/@8131.0/mfold.pyf'
> Post-processing...
>        Block: mfold
>                        Block: au_pen
> Building modules...
>        Building module "mfold"...
>                Creating wrapper for Fortran function "au_pen"("au_pen")...
>                Constructing wrapper function "au_pen"...
>                  au_pen = au_pen(i,j)
>                Constructing COMMON block support for "bigstuff"...
>                  vst,wst,marks,force2
>                Constructing COMMON block support for "chars"...
>                  seq,aux,lorc,usage,seqlab
>                Constructing COMMON block support for "main"...
>                  maxpen,newnum,hstnum,force,strand,numseq,work,wmb,w5,w3,cntrl,
> nsave,list,listsz,basepr,heapi,heapj,n,break_bn,vmin,num,numtloops,numtriloops,m
> axbp
>                Constructing COMMON block support for "efiles"...
>                  asint3,asint5,bulge,dangle,eparam,hairpin,inter,poppen,sint2,s
> int4,sint6,stack,tloop,triloop,tstkh,tstki,prelog
>        Wrote C/API module "mfold" to file "/tmp/@8131.0/mfoldmodule.c"
>        Fortran 77 wrappers are saved to "/tmp/@8131.0/mfold-f2pywrappers.f"
> running build_flib
> running find_fortran_compiler
> detecting Absoft Fortran compiler...
> f77 -V -c /tmp/@8131.1__dummy.f -o /tmp/@8131.1__dummy.o
> found f77: Sun WorkShop 6 update 2 FORTRAN 77 5.3 Patch 111691-07 2004/04/23
> detecting SGI Fortran compiler...
> f77 -version
> 256: f77: Warning: Option -version passed to ld, if ld is invoked, ignored other
> wise
> detecting Sun Fortran compiler...
> f90 -V
> found f90: Sun WorkShop 6 update 2 Fortran 95 6.2 Patch 111690-10 2003/08/28
> f90 -dryrun __dummy.f
> using Sun WorkShop Fortran compiler
>  building 'mfold' library
> f77  -pic  -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib -I/home/OPNSRC/PYT
> HON-2.2.2/lib/python2.2/site-packages/f2py2e/src  -c au_pen.f -o /tmp/@8131.0/au
> _pen.o
> au_pen.f:
>        au_pen:
> "rna.inc", line 24: Warning: local variable "w5" never used
> "rna.inc", line 24: Warning: local variable "w3" never used
> "rna.inc", line 26: Warning: local variable "vmin" never used
> "rna.inc", line 26: Warning: local variable "num" never used
> "rna.inc", line 26: Warning: local variable "numtloops" never used
> "rna.inc", line 28: Warning: local variable "poppen" never used
> "rna.inc", line 29: Warning: local variable "sint2" never used
> f77  -pic  -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib -I/home/OPNSRC/PYT
> HON-2.2.2/lib/python2.2/site-packages/f2py2e/src  -c /tmp/@8131.0/mfold-f2pywrap
> pers.f -o /tmp/@8131.0/mfold-f2pywrappers.o
> /tmp/@8131.0/mfold-f2pywrappers.f:
>        f2pywrapau_pen:
>        f2pyinitbigstuff:
>        f2pyinitchars:
>        f2pyinitmain:
>        f2pyinitefiles:
> ar -cur /tmp/@8131.0/libmfold.a /tmp/@8131.0/au_pen.o /tmp/@8131.0/mfold-f2pywra
> ppers.o
> ranlib  /tmp/@8131.0/libmfold.a
> running build_ext
> replacing linker_so 'gcc -shared' with 'f77'
> building 'mfold' extension
> gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/home/OPNSRC/PYTHON-2.2.2/
> lib/python2.2/site-packages/f2py2e/src -I/home/OPNSRC/PYTHON-2.2.2/include/pytho
> n2.2 -c /home/OPNSRC/PYTHON-2.2.2/lib/python2.2/site-packages/f2py2e/src/fortran
> object.c -o /tmp/@8131.0/fortranobject.o
> gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/home/OPNSRC/PYTHON-2.2.2/
> lib/python2.2/site-packages/f2py2e/src -I/home/OPNSRC/PYTHON-2.2.2/include/pytho
> n2.2 -c /tmp/@8131.0/mfoldmodule.c -o /tmp/@8131.0/mfoldmodule.o
> /tmp/@8131.0/mfoldmodule.c:247: warning: function declaration isn't a prototype
> /tmp/@8131.0/mfoldmodule.c:248: warning: function declaration isn't a prototype
> /tmp/@8131.0/mfoldmodule.c:268: warning: function declaration isn't a prototype
> /tmp/@8131.0/mfoldmodule.c:269: warning: function declaration isn't a prototype
> /tmp/@8131.0/mfoldmodule.c:327: warning: function declaration isn't a prototype
> /tmp/@8131.0/mfoldmodule.c:328: warning: function declaration isn't a prototype
> /tmp/@8131.0/mfoldmodule.c:372: warning: function declaration isn't a prototype
> /tmp/@8131.0/mfoldmodule.c:373: warning: function declaration isn't a prototype
> f77 /tmp/@8131.0/fortranobject.o /tmp/@8131.0/mfoldmodule.o -L/tmp/@8131.0 -L/op
> t/SUNWspro/prod/lib -lmfold -lfsu -lF77 -lM77 -lsunmath -lmvec -lf77compat -lm -
> o ./mfold.so -Bdynamic -G
> restoring linker_so 'gcc -shared'
> Removing build directory /tmp/@8131.0
>
>
>
>
>
> Selon powrsurg at gmail.com:
>
> > Hello,
> >
> > I have a large Fortran 77 program which I am trying to import into my
> > Python script. It appears that F2PY is not properly wrapping one of my
> > functions for some reason.
> >
> > Python 2.3.5 (#2, Sep  4 2005, 22:01:42)
> > [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> import mfold
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > ImportError: ./mfold.so: undefined symbol: f2pywrapau_pen_
> >
> > For reference, the function au_pen is defined as:
> >
> >       function au_pen(i,j)
> >       include 'rna.inc'
> >       integer inc2(5,5)
> >       data inc2/0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0/
> >
> >       au_pen = inc2(numseq(i),numseq(j))*eparam(10)
> >       return
> >       end
> >
> > Where rna.inc is simply:
> >
> >       implicit integer (a-z)
> >       integer maxn
> >       include 'maxn.inc'
> >       parameter (fldmax=2*maxn)
> >       parameter (infinity=999999,sortmax=90000)
> >       parameter (sortmaxp1=sortmax+1)
> > c      parameter (mxbits=(maxn*(maxn+1)+29)/30)
> >       parameter (mxbits=2133600)
> >       parameter (maxtriloops=50)
> >       parameter (maxtloops=100)
> >       parameter (maxsiz=200000)
> >
> >       character*1 seq(maxsiz),aux(maxn),lorc
> >       character*4 usage
> >       character*50 seqlab
> >
> > c      integer vst(maxn*maxn),wst(maxn*maxn)
> >       integer vst(64000000),wst(64000000)
> >       integer*2 marks(mxbits),force2(2*mxbits)
> >
> >       integer maxpen,newnum(maxsiz),hstnum(fldmax),force(fldmax),
> >      .        strand(fldmax),numseq(fldmax),work(fldmax,0:2),wmb(fldmax,0:2),
> >      .        w5(-1:maxn),w3(maxn+2),cntrl(10),nsave(2),list(3000,4),
> >      .        listsz,basepr(maxn),heapi(sortmaxp1),heapj(sortmaxp1),
> >      .        n,break_bn,vmin,num,numtloops,numtriloops,maxbp
> >       integer asint3(6,6,5,5,5),asint5(6,6,5,5,5,5,5),bulge(30),
> >      .        dangle(5,5,5,2),eparam(16),hairpin(30),inter(30),poppen(4),
> >      .        sint2(6,6,5,5),sint4(6,6,5,5,5,5),sint6(6,6,25,5,5,5,5),
> >      .        stack(5,5,5,5),tloop(maxtloops,2),triloop(maxtriloops,2),
> >      .        tstkh(5,5,5,5),tstki(5,5,5,5)
> >
> >       real prelog,prec/100.0/
> >
> >       common /chars/ seq,aux,lorc,usage,seqlab
> >
> >       common /bigstuff/ vst,wst,marks,force2
> >
> >       common /main/ maxpen,newnum,hstnum,force,strand,numseq,work,wmb,w5,
> >      .     w3,cntrl,nsave,list,listsz,basepr,heapi,heapj,n,break_bn,vmin,num,
> >      .     numtloops,numtriloops,maxbp
> >       common /efiles/ asint3,asint5,bulge,dangle,eparam,hairpin,inter,poppen,
> >      .        sint2,sint4,sint6,stack,tloop,triloop,tstkh,tstki,prelog
> >
> > c      common /list/ list,listsz
> > c      common /traceback/ basepr
> > c      common /heap/ heapi,heapj,num
> > c      common /bits/marks,force2
> >
> > maxn.inc simply declares maxn as seen below.
> >
> > I am compiling the shared object using the following call:
> >
> > f2py -c mfold.f rna.f misc.f efiles.f sort.f dc.f bits-gnu.f formid.f
> > -m mfold --f77flags="-O3 -fno-automatic -ffixed-line-length-none"
> >
> > Which does lists warnings that seem to relate to the common blocks.
> > When looking at the lines from a version of mfoldmodule.c before
> > working out my bug listed below, it appears that I get lines such as:
> >
> > extern void F_FUNC(f2pyinitbigstuff,F2PYINITBIGSTUFF)();
> > static void f2py_init_bigstuff() {
> >   F_FUNC(f2pyinitbigstuff,F2PYINITBIGSTUFF)(f2py_setup_bigstuff);
> > }
> >
> > ---------
> >
> > The reason for the commented declaratins of mxbits, vst, and wst has
> > to do with what I believe is a bug in F2PY. It seems that F2PY does
> > not allow a previously declared parameter variable to be used twice
> > within the declaration of another parameter varaible. For example,
> >
> >       parameter (maxn=8000)
> >       parameter (mxbits=(maxn*(maxn+1)+29)/30)
> >
> > When looking at the _module.c file F2PY generates, it seems that F2PY
> > replaces the first maxn with 8000, but does not do so for the second
> > and thus creates an error. The only workaround for this was to comment
> > out that line and replace it with the computed value of mxbits.
> >
> > ----------
> >
> > I hope including this all in one e-mail made sense. If someone could
> > help me with this I would GREATLY apprecial it.
> >
> > _______________________________________________
> > f2py-users mailing list
> > f2py-users at cens.ioc.ee
> > http://cens.ioc.ee/mailman/listinfo/f2py-users
> >
>
>
>



More information about the f2py-users mailing list