0

I'm pretty new to Python (~4 months) and I'm trying to use some Fortran subroutines in python but I'm having major problems using f2py. I have looked through the documentation but can't make heads or tails of why I'm getting the errors that I'm getting. I created a small Fortran file hello.f

C File hello.f
      subroutine foo (a)
      integer a
      print*, "Hello from Fortran!"
      print*, "a=",a
      end

And from the command line I'm trying to use the command:

f2py -c -m hello hello.f

but I'm getting this output:

F:\home\tsansom\Projects\PyTxBLEND>f2py -c -m hello hello.f
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 "hello" sources
f2py options: []
f2py:> c:\users\tsansom\appdata\local\temp\tmpt8nrxn\src.win-amd64-2.7\hellomodule.c
creating c:\users\tsansom\appdata\local\temp\tmpt8nrxn\src.win-amd64-2.7
Reading fortran codes...
    Reading file 'hello.f' (format:fix,strict)
Post-processing...
    Block: hello
                    Block: foo
Post-processing (stage 2)...
Building modules...
    Building module "hello"...
            Constructing wrapper function "foo"...
              foo(a)
    Wrote C/API module "hello" to file "c:\users\tsansom\appdata\local\temp\tmpt8nrxn\src.win-amd64-2.7\hellomodule.c"
adding 'c:\users\tsansom\appdata\local\temp\tmpt8nrxn\src.win-amd64-2.7\fortranobject.c' to sources.
adding 'c:\users\tsansom\appdata\local\temp\tmpt8nrxn\src.win-amd64-2.7' to include_dirs.
copying C:\Anaconda\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\users\tsansom\appdata\local\temp\tmpt8nrxn\src.win-amd64-2.7
copying C:\Anaconda\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\users\tsansom\appdata\local\temp\tmpt8nrxn\src.win-amd64-2.7
build_src: building npy-pkg config files
running build_ext
No module named msvccompiler in numpy.distutils; trying from distutils
customize MSVCCompiler
customize MSVCCompiler using build_ext
Unexpected ValueError in C:\Anaconda\lib\site-packages\numpy\distutils\fcompiler\compaq.pyc
Traceback (most recent call last):
  File "C:\Anaconda\Scripts\f2py-script.py", line 23, in <module> 
    main()
  File "C:\Anaconda\lib\site-packages\numpy\f2py\f2py2e.py", line 590, in main
    run_compile()
  File "C:\Anaconda\lib\site-packages\numpy\f2py\f2py2e.py", line 576, in run_compile
    setup(ext_modules = [ext])
  File "C:\Anaconda\lib\site-packages\numpy\distutils\core.py", line 169, in setup
    return old_setup(**new_attr)
  File "C:\Anaconda\lib\distutils\core.py", line 151, in setup
    dist.run_commands()
  File "C:\Anaconda\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Anaconda\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Anaconda\lib\site-packages\numpy\distutils\command\build.py", line 39, in run
    old_build.run(self)
  File "C:\Anaconda\lib\distutils\command\build.py", line 127, in run
    self.run_command(cmd_name)
  File "C:\Anaconda\lib\distutils\cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "C:\Anaconda\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Anaconda\lib\site-packages\numpy\distutils\command\build_ext.py", line 195, in run
    c_compiler=self.compiler)
  File "C:\Anaconda\lib\site-packages\numpy\distutils\fcompiler\__init__.py", line 837, in new_fcompiler
    load_all_fcompiler_classes()
  File "C:\Anaconda\lib\site-packages\numpy\distutils\fcompiler\__init__.py", line 740, in load_all_fcompiler_classes
    __import__ (module_name)
  File "C:\Anaconda\lib\site-packages\numpy\distutils\fcompiler\compaq.py", line 57, in <module>
    class CompaqVisualFCompiler(FCompiler):
  File "C:\Anaconda\lib\site-packages\numpy\distutils\fcompiler\compaq.py", line 100, in CompaqVisualFCompiler
    raise e
ValueError: [u'path', u'lib']

Anyone know what this error means? Admittedly I don't really know what I'm doing but I'm trying to learn. Thanks in advance for the help, it's much appreciated. Thanks

Taylor
  • 378
  • 2
  • 4
  • 14
  • Looking at the current code for "compaq.py" (https://github.com/numpy/numpy/blob/fbd6510d58a47ea0d166c48a82793f05425406e4/numpy/distutils/fcompiler/compaq.py) it looks like it might be an exception that should be ignored but isn't being handled correctly. Try changing the line `if not "path']" in str(e):` to `if not 'path' in e.args:`? (It's a shot in the dark, and I can't do test it since I don't have compaq fortan, but it might work...) – DavidW Jul 15 '15 at 12:53
  • not sure this will help you, but this works for me using gfortran on a mac. So it looks like the issue is with the compaq compiler, not your code. do you have an alternative fortran compiler you can use (using the `f2py --fcompiler=` option)? – tmdavison Jul 21 '15 at 15:20

0 Answers0