1

I am trying to import a fortran subroutine into python code. Following this guide https://notmatthancock.github.io/2017/02/10/calling-fortran-from-python.html I have added the following line into my fortran code:

!f2py intent(in) :: ear,ne,parames,ifl
!f2py intent(out) photar,photer

However when I try to use f2py -c fireball_ES_param.f -m fireball to create fireball.so to import in my python code I get several hundreds of warnings, which might be the problem but I am not sure: https://www.4shared.com/s/f2ynHZ_Wjda (it's too long to be posted here).

In any case, the fireball.cpython-34m.so file gets created, but when I try to import that from python I get:

$ python

Python 2.7.6 (default, Nov 13 2018, 12:45:42)  [GCC 4.8.4] on
linux2 Type "help", "copyright", "credits" or "license" for more
information.
>>> import fireball Traceback (most recent call last):
File "<stdin>", line 1, in <module> ImportError:
  No module named fireball

I tried:

import sys

sys.path.append('/path/to/folder/containing/fireball.cpython-34m.so')

but got the same result. I am not sure if there is a problem with the creation of fireball.so, or with its import.

9
  • First comment: f2py uses Python 3.4 (as can be seen from the filename of the module) while you try tro import it in Python 2.7 Commented May 31, 2019 at 10:06
  • One solution: import the code in Python 3.4 instead of Python 2.7. Other solution: see if you have f2py also for Python 2.7 Commented May 31, 2019 at 10:06
  • sadly, using 3.4 did not bring any difference Commented May 31, 2019 at 13:03
  • where is the .so file located? Commented May 31, 2019 at 13:14
  • in the same folder where I start python, I also manually include the folder into the paths searched by python with sys.path.append('/path/to/folder/containing/fireball.cpython-34m.so'), but nothing changes Commented May 31, 2019 at 14:48

1 Answer 1

1

f2py links to Python 3.4 (hence the 34 in fireball.cpython-34m.so) but python3 is actually version 3.6 (see you last comment).

Your options:

  • Start your program with Python 3.4 which should be available as python3.4
  • Update f2py to Python 3.6. If you installed via pip, pip install --user -U numpy should do. Then rebuild the extension.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.