Numpy distutils howto

Iva*_*ets 8 python distutils numpy f2py

我花了将近一个小时来搜索解决方案,但numpy.distutils的文档非常稀疏.

我有一个f2py包装的模块.它基本上由3个文件组成:

a.f90
a.pyf
lib.a <- this is a static library that contains most of the computational code
Run Code Online (Sandbox Code Playgroud)

使用以下shell-script命令很好地编译该模块.

f2py --build-dir temp -c a.pyf a.f90 lib.a --fcompiler=gnu95   
--fcompiler-flags="Zillions of compiler options"
Run Code Online (Sandbox Code Playgroud)

结果,我有python模块a.so(名称在.pyf文件中指定).

我如何使用numpy.distutils(或其他一些面向python的构建工具)来做到这一点?一个不太重要的问题是,我是否还可以包含lib.a的依赖(并在必要时重建它?)

Iva*_*ets 5

所以,谷歌搜索不是1小时,谷歌搜索需要2天,但最终我找到了这样做的方法.希望,这会对某人有所帮助.

  def configuration(parent_package='',top_path=None):
      from numpy.distutils.misc_util import Configuration, get_info
      config = Configuration('a', parent_package, top_path)
      lib = ['./libdir/lib.a']
      src = ['a.f90','a.pyf']
      inc_dir = ['libdir']              
      config.add_extension('mya',sources=src,depends=lib_tt,
                      include_dirs=inc_dir,extra_objects="lib.a")
      #The main trick was to use extra_objects keyword
      return config

  if __name__ == '__main__':
      from numpy.distutils.core import setup
      setup(**configuration(top_path='').todict())
Run Code Online (Sandbox Code Playgroud)