找到你要的答案

Q:Install f2py with python3

Q:安装f2py和Python3

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?

我需要从Python调用Fortran模块。我做f2py和python2.7。它工作得很好。

现在,我要用它与Python3但f2py似乎并不兼容Python3。

我看到一些人使用一个版本称为f2py3,但它既可通过画中画,不通过MacPorts(我用的是Mac)。另外,Python3 + NumPy + f2py似乎已经集成在费多拉。

有人已经利用f2py3(或同等学历)在Mac Python3?如果不是,什么替代解决你提出的Fortran库Python3链接?

answer1: 回答1:

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.

作为替代,你可以使用‘和fortran-iso-c-binding调用FORTRAN程序不依赖f2py。这种方法的缺点是需要自己指定接口。

下面是我在前段时间发布的一个例子。

python  python-3.x  fortran  osx-mavericks  f2py