2

How to use F2Py through Python instead of calling it in command line?

I have a portable Python in use, am not able to install Python. Thus it is not possible to install packages except those work if I unzip the package and copy all to the folder 'site-packages'. Having these mentioned, it is also impossible to change environmental variables, i.e., path (cannot be changed, appended;) though it is not possible to call commands 'F2Py' in short form.
Although F2Py is part of numpy and numpy is installed in the portable Python, there is no 'F2Py.py' installed anywhere.
The question is how to use F2Py to compile Fortran code being used in Python considering the access limtation etc?
Note that there is a GFortran binary unpacked in a folder.

4

1 回答 1

2

虽然我不太明白你的解释,但从第一句话看来,你想要做的是f2py -c -m hello hello.f在 python 中得到相当于:

from numpy import f2py
f2py.compile(open('hello.f').read(), 'hello')
于 2012-01-07T11:47:10.173 回答