mgaitan / fortran_magic

An extension for IPython/Jupyter that helps to use Fortran in your interactive session.
BSD 3-Clause "New" or "Revised" License
117 stars 32 forks source link

fortranmagic should call f2py3 under Python 3 #9

Closed vallis closed 8 years ago

vallis commented 9 years ago

Otherwise it will silently use an f2py that may have a hardcoded #!/usr/bin/python27 at the top, resulting in puzzling errors because the compiled objects look at the wrong Python includes.

mgaitan commented 9 years ago

Hey @vallism, you are right, thanks for the report.

This bug was introduced after #8 . Before that, instead to run the command f2py via a subprocess call, we directly called the f2py.main() function.

I'm not sure if the better idea is to undo that change and handle the Window's problem it fixes with a different approach, or make the call to the proper f2py script depending the python version.

For the latter, I'm not sure if append the python version would be enough. For example, in my computer (w/ubuntu) I have these:

tin@morochita:~/lab/fortran_magic$ f2py<tab>
f2py     f2py2.7  f2py3.4  

but is this common to any system/os?

vallis commented 9 years ago

This may be a question for the numpy.f2py developers. I looked in their github, and there's no mention of f2py3, so I suspect that it may be something that packagers add.

On my anaconda Python 2.7 + 3.4 installation on OS X, I have f2py under the main /bin directory, and f2py3 under the python 3 sub-environment. On my homebrew Python 2.7 + 3.4 installation, I have only f2py2.7 in /usr/local/bin; the pip-installed numpy creates f2py for both Python 2.7 and 3, but with the wrong hash-bang... Basically, it's all over the place.

Perhaps you could do the awkward thing, and call f2py.main on anything else than windows. Another solution, less transparent to the user but still OK IMHO, would be to allow selecting the f2py executable in the iPython magic.

mgaitan commented 9 years ago

Maybe the great numpy's maintainers @charris or @juliantaylor can help us: Is there a multiplatform python2/3 compatible way to run f2py programatically (i.e from Python) ?

juliantaylor commented 9 years ago

should just be numpy.f2py.compile

the f2py binary is just a wrapper around numpy.f2py functions so you should be able to do everything from python

juliantaylor commented 9 years ago

no idea why it originally doesn't work for windows directly from python. that would be interesting to figure out but i have no windows. otherwise maybe one can use the python -m thing (pep338), with python being sys.executable, though I have no idea if that invocation method works with f2py, but that should be fixable if not

juliantaylor commented 9 years ago

too bad doesn't work, but added https://github.com/numpy/numpy/pull/5565

astrojuanlu commented 8 years ago

I just checked and replacing the f2py call with python -m numpy.f2py works, but it requires NumPy 1.10 (see https://github.com/numpy/numpy/commit/29c019a7f5e348b31daf946bfcc45e72482159b6). Since it seems to be the simplest solution, @mgaitan would you accept a pull request with this change and tag a new release?