F2PY doesn't find a module

不羁的心 提交于 2019-12-02 04:46:37

问题


I am having difficulty with getting a f2py compiled module work in Python.

I have a piece of software written in Fortran that compiles well on a Linux 64bit machine. Further on F2Py compiles a Python module that uses Fortran bits as well.

Here is how the Python module is compiled:

f2py --fcompiler=gfortran -I"path-to-dir-with-mod-files" -c -m mod_landems mod_landem.f90

But once I want to import that module I get an error (in Ipython):

----> 1 import mod_landems
ImportError: ./mod_landems.so: undefined symbol: __nesdis_landem_module_MOD_nesdis_landem

To be honest I am confused with this error. Search did not help much so I need to ask you here: how can I possibly make it work? If I put the python module code in the same directory as where the mod files are it produces same error message.

Here is a piece of my (primitive) code:

module n_landem
implicit none

! INPUT VARIABLES
real(8) Angle
real(8) Sm_Content
real(8) Veg_Frac
real(8) Soil_Temp
real(8) Land_Temp
real(8) Snow_Depth
real(8) Frequency

! OUTPUT VARIABLES
real(8) Emis_H
real(8) Emis_V

contains

subroutine landem

  USE NESDIS_LANDEM_MODULE
  USE TYPE_KINDS, ONLY : fp

  call NESDIS_LandEM(Angle,Frequency,Sm_Content,Veg_Frac,Soil_Temp,Land_Temp,Snow_Depth,Emis_H,Emis_V)
end subroutine landem
end module n_landem

If I recall correctly some time ago this module was importable, but can't seem to make it work on either debian64 installation or debian32bit computer.


回答1:


in your f2py call, you have to pass the libraries you are linking explicitly with '-l', the same you would pass it to your Fortran compiler (i.e. gfortran). Therefore, does

f2py -c --fcompiler=gfortran -I"path-to-dir-with-mod-files" --fcompiler=gfortran -I"path-to-dir-with-mod-files" -lNESDIS_LandEM_Module -m mod_landems mod_landem.f90 -m mod_landems mod_landem.f90

work for you ?

Best, Max.




回答2:


I'm working on a similar project and too am new to Fortran. Using the reference below I found that you import the fortran module just as you would import a library and then call a function similarly. http://cens.ioc.ee/projects/f2py2e/usersguide/#the-quick-and-smart-way



来源:https://stackoverflow.com/questions/14681068/f2py-doesnt-find-a-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!