2

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

user3060854
  • 923
  • 2
  • 15
  • 25
  • 1
    Double check that your script is in the same directory as where you were running the command. Also please update your post with any error messages you're getting or at least a better description of what "it doesn't work" means – wnnmaw Dec 27 '13 at 20:53
  • @wnnmaw -- Exactly. "It doesn't work" is not a statement of a problem. We need to know what doesn't work if we have any hope of helping. – mgilson Dec 27 '13 at 21:03
  • This might be something you can fix by switching from ```os.system()``` to ```subprocess.popen()```. I've read a few things like [this](http://www.logilab.org/blogentry/20469) that seem to suggest that its more powerful/less error prone. I've not been able to figure it out though, so good luck. Perhaps [this](http://stackoverflow.com/questions/12605498/how-to-use-subprocess-popen-python) will help? – wnnmaw Dec 27 '13 at 21:47

1 Answers1

1

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

user3060854
  • 923
  • 2
  • 15
  • 25