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

3
  • 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 Commented Dec 27, 2013 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. Commented Dec 27, 2013 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 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 will help? Commented Dec 27, 2013 at 21:47

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

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.