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.

1 Answer 1

2

Although I don't really understand your explanation, from the first sentence it would seem that what you want to do is to get the equivalent of f2py -c -m hello hello.f in python:

from numpy import f2py
f2py.compile(open('hello.f').read(), 'hello')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. It does work if you have installed Python and GFortran, however for my case both are just unpacked. There is no registry info associated with them. Thus the code provided didn't work for me.

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.