Python numpy/f2py链接库

Python numpy/f2py链接库,python,numpy,linker,fortran,f2py,Python,Numpy,Linker,Fortran,F2py,我正在尝试使用f2py为我的一个fortran程序制作一个包装器。我的fortran程序使用外部库,当我尝试链接它们时,会出现一个错误,提示: gfortran:f77: /var/folders/46/l1mrxgls07s6tpwb6tgpvhpr0000gn/T/tmpPCM7Ne/src.macosx-10.9-intel-2.7/progs-f2pywrappers.f Traceback (most recent call last): File "/System/Library

我正在尝试使用f2py为我的一个fortran程序制作一个包装器。我的fortran程序使用外部库,当我尝试链接它们时,会出现一个错误,提示:

gfortran:f77: /var/folders/46/l1mrxgls07s6tpwb6tgpvhpr0000gn/T/tmpPCM7Ne/src.macosx-10.9-intel-2.7/progs-f2pywrappers.f
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/bin/f2py", line 24, in <module>
    main()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/f2py/f2py2e.py", line 588, in main
    run_compile()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/f2py/f2py2e.py", line 574, in run_compile
    setup(ext_modules = [ext])
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/core.py", line 186, in setup
    return old_setup(**new_attr)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/command/build.py", line 37, in run
    old_build.run(self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build.py", line 127, in run
    self.run_command(cmd_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/command/build_ext.py", line 232, in run
    self.build_extensions()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_ext.py", line 448, in build_extensions
    self.build_extension(ext)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/command/build_ext.py", line 425, in build_extension
    build_temp=self.build_temp,**kws)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 691, in link_shared_object
    extra_preargs, extra_postargs, build_temp, target_lang)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/fcompiler/__init__.py", line 643, in link
    libraries)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/ccompiler.py", line 571, in gen_lib_options
    runtime_library_dirs, libraries)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 1086, in gen_lib_options
    lib_file = compiler.find_library_file([lib_dir], lib_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 777, in find_library_file
    raise NotImplementedError
我对解决这个问题需要做些什么感到有点困惑,因为我是Python新手。似乎这个方法还没有实现。我只需要实现它吗?我该如何具体实现这一点?进行此更改时是否需要重新生成f2py可执行文件?如果是的话,我会怎么做


谢谢

这里没有回答这个问题,但它确实说明了一种解决方法(直接引用所有的*.o文件,而不是将它们放在库中)。而且,这是一篇非常好的文章,用来解释关于f2py的一些事情

f2py-c--fcompiler=gfortran-I.libtest.o-m Main.f90


如果您的库基于单个文件,那么这将起作用。如果您的库(更有可能)基于多个文件,只需包含完整的*.o名称即可。

我有同样的问题:我的f2py命令是:
f2py-lc:/pytm/lib-m main-c main.f90
我遵循了这里的说明:实际上,这是一个抽象方法(请参阅)我想f2py或numpy.distutils必须在某个地方实现它。我有完全相同的问题。我试图按照以下指南安装scipy:并抛出此错误。您是如何解决此问题的?可以找到如何使用*.o文件解决此问题的示例
def find_library_file (self, dirs, lib, debug=0):
        """Search the specified list of directories for a static or shared
        library file 'lib' and return the full path to that file.  If
        'debug' true, look for a debugging version (if that makes sense on
        the current platform).  Return None if 'lib' wasn't found in any of
        the specified directories.
        """
        raise NotImplementedError