问题描述
我需要在Python中调用来自Fortran模块的例程。我用 f2py
和 python2.7
做了它。它工作得很好。
现在,我必须将它与 python3
使用,但 f2py
似乎不兼容 python3
。
我看到一些人使用一个名为 f2py3
的版本,但它不能通过 pip
获得,而不是通过macports(我正在使用Mac)。另外,。
有人设法将 f2py3
(或其等价物)与<$ c Mac上的$ c> python3 ?如果没有,您建议使用什么替代解决方案将Fortran库与 python3
?
另外,您可以使用可以在不依赖f2py的情况下调用Fortran例程。这种方法的缺点是你需要自己指定接口。
以下是我前一段时间发布在SO上。
I need to call routines from Fortran modules within Python. I did it with f2py
and python2.7
. It worked pretty well.
Now, I have to use it with python3
but f2py
does not seem to be compatible with python3
.
I see that some people use a version called f2py3
, but it is neither available through pip
, not through macports (I am using a Mac). Also, python3+numpy+f2py seem to be already integrated in Fedora.
Does anyone have managed to use f2py3
(or its equivalent) with python3
on a Mac? If not, what alternate solution do you propose to link Fortran libraries with python3
?
As an alternative, you can use ctypes and fortran-iso-c-binding to call Fortran routines without relying on f2py. The downside of this approach is that you need to specify the interfaces yourself.
Here is an example I posted on SO some time ago.
这篇关于用python3安装f2py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!