8

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?

3
  • I'm interested in this also. FYI, your Fedora link above returns no results when I try it but I get some info just searching for 'f2py' via your link. Commented Mar 5, 2016 at 22:54
  • I fixed the broken link. It should point on the download pages of the RPM resource for python3-numpy-f2py. Commented Mar 7, 2016 at 5:18
  • yeah, works now. thanks! Commented Mar 7, 2016 at 5:22

2 Answers 2

5

As an alternative, you can use and 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.

Sign up to request clarification or add additional context in comments.

2 Comments

Very interesting because f2py does not seem to be maintained anymore (maybe I am wrong?). The problem is that I need to use a lot of old fortran codes. Refactoring interfaces is not an easy task and can generate errors. But for sure, I'll use you suggestion for new codes.
Well, for old code you could use compiler options to influence the generated function names (e.g. -fno-underscoring for gfortran) and try to call the routines from python directly (without the ISO_C_Bindings). Then all the work would need to be done on the Python side. Note that this is (in general) not portable, and depends on the compiler used!
2

f2py comes with numpy and based on this January 2020 activity on github, it seems clear that f2py is currently maintained.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.