Intel® Distribution for Python*
Engage in discussions with community peers related to Python* applications and core computational packages.

How to call a fortran static library from python

Juan_David_V_
Beginner
1,084 Views

Hello.

I have a fortran static library and I need to call it from python. Can somebody give me an example of how to do that.

0 Kudos
6 Replies
gaston-hillar
Valued Contributor I
1,084 Views

Juan David,

I do believe F2py is what you need. F2py makes it easy to construct extension modules that interfaces to routines in Fortran 77/90/95 code.

​The following URL will provide you with some examples on how to use F2py, aka f2py: http://docs.scipy.org/doc/numpy-1.10.1/user/c-info.python-as-glue.html

 

0 Kudos
gaston-hillar
Valued Contributor I
1,084 Views

Juan David,

The following link will also provide you useful information about F2py, aka f2py: http://docs.scipy.org/doc/numpy-dev/f2py/usage.html

The documentation includes detailed about both the module and the command-line interface.

0 Kudos
gaston-hillar
Valued Contributor I
1,084 Views

Juan David,

Let me know whether the information I provided you has helped you. Feel free to add any additional comments to this thread in case you need more details. I've been mixing Fortran with Python in the last months. :)

0 Kudos
Juan_David_V_
Beginner
1,084 Views

Hello Gastón.

I use this command: f2py -c -m CoreSolver CoreSolver.lib but I get the next error: Unable to find vcvarsall.bat. I have to say that the static library use imsl library, maybe this could be problematic.

Thanks for the help

0 Kudos
gaston-hillar
Valued Contributor I
1,084 Views

Juan David,

The one you mention is a typical problem with f2py.

You can find helpful information to solve this problem in the following thread: https://code.google.com/archive/p/rdflib/issues/104#c4

Few years ago, there was a Numpy discussion about this issue that is the most referenced one and will definitely help you: https://www.mail-archive.com/numpy-discussion@scipy.org/msg30016.html. This one links to the previously mentioned thread.

Hope it helps.

 

0 Kudos
gaston-hillar
Valued Contributor I
1,084 Views

Juan David,

In case the solution provided was useful, don't forget to provide feedback to this thread. This way, whenever somebody has a similar problem, he/she will search within the forums, find this thread and know that the solutions provided have solved your issue.

0 Kudos
Reply