user3060854
user3060854

Reputation: 933

how to run f2py inside python code

I am using python 2.7 under Linux Mint and I have some fortran code which I import into python code using f2py.

So I type in terminal:

f2py -c my_module.f90 -m my_module

and it works fine.

Now I want to use f2py not in terminal but inside python code. I have tried something like

import os
os.system("f2py -c my_module.f90 -m my_module")

but it doesn't work. That's what I get:

running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "module_name" sources
f2py options: []
f2py:> /tmp/tmpfhVUFI/src.linux-x86_64-2.7/module_namemodule.c
creating /tmp/tmpfhVUFI
creating /tmp/tmpfhVUFI/src.linux-x86_64-2.7
Reading fortran codes...
Post-processing...
Post-processing (stage 2)...
Building modules...
error: f2py target file '/tmp/tmpfhVUFI/src.linux-x86_64-2.7/module_namemodule.c' not generated

Both fortran and python code are located in the same directory

I guess that I may have to use distutils, but I don't know how

Any thought will be helpfull

Thank you

Upvotes: 2

Views: 915

Answers (1)

user3060854
user3060854

Reputation: 933

I am sorry, it was my mistake. Some other issues in the code were responsible for the problem.

This method:

import os
os.system("f2py -c my_module.f90 -m my_module")

works fine.

This question may be concidered closed.

Thank you for your time

Upvotes: 1

Related Questions