setup.py适用于依赖于cython和f2py的软件包

abe*_*gou 19 python numpy cython f2py

我想为python包创建一个setup.py脚本,其中包含几个依赖于cython和f2py的子模块.我试图使用setuptools和numpy.distutils,但到目前为止失败了:

使用setuptools

我可以使用setuptools编译我的cython扩展(并为包的其余部分创建一个安装).但是,我无法弄清楚如何使用setuptools来生成f2py扩展.经过广泛的搜索,我只发现了像这样的消息,声明必须使用numpy.distutils编译f2py模块.

使用numpy.distutils

我可以使用numpy.distutils编译我的f2py扩展(并为包的其余部分创建安装).但是,我一直无法弄清楚如何让numpy.distutils编译我的cython扩展,因为它总是尝试使用pyrex来编译它(我使用的是特定于cython的扩展).我已经做了一个搜索来弄清楚如何为cython文件获取numpy.distutils - 至少在一年前 - 他们建议将一个猴子补丁应用于numpy.distutils.似乎应用这样的猴子补丁也限制了可以传递给Cython的选项.

我的问题是:为依赖于f2py和cython的软件包编写setup.py脚本的推荐方法是什么?是否应用numpy.distutils补丁真的要走了吗?

小智 6

您可以在 setup.py 中分别调用每个,如
http://answerpot.com/showthread.php?601643-cython%20and%20f2py

# Cython extension
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
  ext_modules = [Extension( 'cext', ['cext.pyx'] )],
  cmdclass = {'build_ext': build_ext},
  script_args = ['build_ext', '--inplace'],
)

# Fortran extension
from numpy.distutils.core import setup, Extension
setup(
  ext_modules = [Extension( 'fext', ['fext.f90'] )],
)
Run Code Online (Sandbox Code Playgroud)

您的调用上下文(我认为他们称此命名空间,不确定)
必须更改当前对象 Extension 和函数
setup() 是什么。

第一个 setup() 调用,它是 distutils.extension.Extension
和 distutils.core.setup()

第二个 setup() 调用,它是 numpy.distutils.core.Extension
和 numpy.distutils.core.setup()

  • 不幸的是,answerpot.com 链接不再有效。不过还是谢谢你的回答!:-) (2认同)