我正在尝试使用f2py将fortran代码编译到共享库中以在Windows 10上的python中导入和使用。(它在我的Linux分区上工作正常。)我安装了anaconda,并使用conda install
我已安装numpy,scipy,jupyter和matplotlib,都没有错误。我再次使用anaconda使用conda install mingw
安装fortran编译器,没有任何问题。我跑的时候
python C:\Users\user_name\Anaconda2\Scripts\f2py.py -c --fcompiler=gnu95 --compiler=mingw32 -m foo foo.f
我得到以下输出(底部有错误信息):
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "foo" sources
f2py options: []
f2py:> c:\users\user_name\appdata\local\temp\tmpseovl0\src.win-amd64-2.7\foomodule.c
creating c:\users\user_name\appdata\local\temp\tmpseovl0\src.win-amd64-2.7
Reading fortran codes...
Reading file 'foo.f' (format:fix,strict)
rmbadname1: Replacing "index" with "index_bn".
rmbadname1: Replacing "index" with "index_bn".
rmbadname1: Replacing "index" with "index_bn".
rmbadname1: Replacing "index" with "index_bn".
rmbadname1: Replacing "index" with "index_bn".
rmbadname1: Replacing "index" with "index_bn".
Post-processing...
Block: foo
Block: calculate
Block: delan
Block: chg
Block: del
Block: vext
Block: pwm
Block: rlg
Block: gshell
Block: pwmg
Block: vhf
Block: hf
Block: exsfnd
Block: exscal
Block: exs
Block: ch
Block: factor
Block: engan
Block: tred3
Block: bisect
Block: tinvit
Block: trbak3
Post-processing (stage 2)...
Building modules...
Building module "foo"...
Constructing wrapper function "calculate"...
rhor,rhoi,delr,deli,spenergy,xcenergy,intenergy,totenergy = calculate(nsh,memsh,ivec,gmags,vextr,vexti,vmagsr,vmagsi,np,nq,nlan,ifill,e2byal,spenergyfn,[js,jt,eps,nx,nkx,niter,alf,logfn])
Constructing wrapper function "delan"...
delan(delr,deli,nsh,memsh,nlan)
Constructing wrapper function "chg"...
chg(nlan,delr,deli,rhor,rhoi,nsh,memsh,ivec,q0,js,jt,eps)
Constructing wrapper function "del"...
del(q0,nsh,vmagsr,vmagsi,memsh,nq,np,ivec,js,jt,eps,nj,nlan,nkx,nx,delr,deli,ifill,e2byal,delrsv,delisv)
Constructing wrapper function "vext"...
vext(q0,nsh,vmagsr,vmagsi,memsh,nq,np,ivec,js,jt,eps,nj,nlan,hr,hi,rkx,x)
Constructing wrapper function "pwm"...
pwm(np,n,qx,qy,f)
Creating wrapper for Fortran function "rlg"("rlg")...
Constructing wrapper function "rlg"...
rlg = rlg(alf,x,n)
Constructing wrapper function "gshell"...
ish,nsh,ivec,gmags = gshell(js,jt,eps,gmax)
Constructing wrapper function "pwmg"...
pwmg(n,m,qx,qy,f)
Constructing wrapper function "vhf"...
vhf(q0,nsh,e2byal,memsh,nq,np,ivec,js,jt,eps,nj,nlan,hr,hi,xcr,xci,rkx,x,delr,deli)
Constructing wrapper function "hf"...
hf(delr,deli,im,ish,n1,n2,gx,gy,hxr,hxi,xr,xi,nlan)
Constructing wrapper function "exsfnd"...
exsfnd(n1,m1,n2,m2,ish,exsval,nlan)
Constructing wrapper function "exscal"...
exscal(nlan,gmags,nsh)
Constructing wrapper function "exs"...
exs(ip1,ip2,ip3,ip4,l,gmag,exsval)
Creating wrapper for Fortran function "ch"("ch")...
Constructing wrapper function "ch"...
ch = ch(a,b,x)
Creating wrapper for Fortran function "factor"("factor")...
Constructing wrapper function "factor"...
factor = factor(k)
Constructing wrapper function "engan"...
engan(q0,nsh,vmagsr,vmagsi,memsh,nq,np,ivec,js,jt,eps,nj,nlan,nkx,nx,delr,deli,ifill,e2byal,esp,exc,eint,etot,energyfn)
Constructing wrapper function "tred3"...
tred3(ar,ai,d,e,e2,tau,[n,nv])
Constructing wrapper function "bisect"...
bisect(eps1,d,e,e2,lb,ub,m,w,ind,ierr,rv4,rv5,[n,mm])
Constructing wrapper function "tinvit"...
tinvit(d,e,e2,w,ind,z,ierr,rv1,rv2,rv3,rv4,rv6,[nm,n,m])
Constructing wrapper function "trbak3"...
trbak3(ar,ai,tau,zr,zi,[nm,n,nv,m])
Constructing COMMON block support for "exspas"...
exssto,nsto,nvlan
Wrote C/API module "foo" to file "c:\users\user_name\appdata\local\temp\tmpseovl0\src.win-amd64-2.7\foomodule.c"
Fortran 77 wrappers are saved to "c:\users\user_name\appdata\local\temp\tmpseovl0\src.win-amd64-2.7\foo-f2pywrappers.f"
adding 'c:\users\user_name\appdata\local\temp\tmpseovl0\src.win-amd64-2.7\fortranobject.c' to sources.
adding 'c:\users\user_name\appdata\local\temp\tmpseovl0\src.win-amd64-2.7' to include_dirs.
copying C:\Users\user_name\Anaconda2\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\users\user_name\appdata\local\temp\tmpseovl0\src.win-amd64-2.7
copying C:\Users\user_name\Anaconda2\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\users\user_name\appdata\local\temp\tmpseovl0\src.win-amd64-2.7
adding 'c:\users\user_name\appdata\local\temp\tmpseovl0\src.win-amd64-2.7\foo-f2pywrappers.f' to sources.
build_src: building npy-pkg config files
running build_ext
Looking for python27.dll
Building import library (arch=AMD64): "C:\Users\user_name\Anaconda2\libs\libpython27.a" (from C:\Users\user_name\Anaconda2\python27.dll)
error: [Error 2] The system cannot find the file specified
我可能会偏离基础,但它看起来像编译顺利,并且在尝试组合python模块时发生错误。文件C:\Users\user_name\Anaconda2\python27.dll
存在。文件C:\Users\user_name\Anaconda2\libs\libpython27.a
不存在。我检查过我能够在文件夹(C:\Users\user_name\Anaconda2\libs\
)中创建文件。
答案 0 :(得分:0)
我刚才遇到了类似设置的问题(尽管使用的是Windows 7)。过了一会儿,我发现安装libpython包(conda install libpython
)似乎已经解决了。
我认为使用here描述的gendef
/ dlltool
方法也可以解决问题。