3

I am trying to run a simple Fortran subroutine using numpy.f2py as described on: http://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html#calling-f2py-from-python

When I try to compile (f2py.compile(source, modulename='add')) from python I get the following error:

"Could not locate executable C:Python27pythonw.exe
Executable C:Python27pythonw.exe does not exist"

Looking for this file I found that C:\Python27\pythonw.exe does exist in my system, so could it possible be a problem with the path?

In any case, any advice on how to make my code work?

Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68
Lene
  • 31
  • 1
  • 5
  • 1
    The error message doesn't have slashes. Perhaps it's looking in directory "C:" for an executable named "Python27pythonw"? – Kevin Oct 04 '13 at 14:35
  • Yes, I think it is.. but what can I do about it? – Lene Oct 04 '13 at 14:37
  • I upvoted the question, because I am having the exact same problem. Somehow f2py gets a bad executable name or loses the double slashes in the process. I had a look at the source code, but I was not able to determine where it comes from. I guess the problem must lie somewhere in the __init__.py file from f2py. The weird thing is that calling f2py from the command line does work. PS: same code works on ubuntu – Ben K. Nov 07 '13 at 07:39

2 Answers2

2

I found a quick fix for the problem. However, I cannot guarantee that nothing else will break when using this.

In the file:

C:\Python27\Lib\site-packages\numpy\f2py\__init__.py

in line 40, change

s,o = exec_command(c)

to

s = os.system(c)

It seems that the main error lies in numpy.distutils.exec_command, which seems to omit the backslashes when calling python. Again, I may be playing with forces I do not understand, by replacing the more involved exec_command by os.system call. But it works for me.

Ben K.
  • 1,160
  • 6
  • 20
0

Another approach without "losing" o (output) in s = os.system(c) is to implement

c = c.replace("\\", "\\\\")

before s,o = exec_command(c) or status, output = exec_command(c).

Renatius
  • 542
  • 1
  • 3
  • 11