setup.py 用于同时依赖 cython 和 f2py 的包
我想为 python 包创建一个 setup.py 脚本,其中包含几个依赖于 cython 和 f2py 的子模块。我尝试使用 setuptools 和 numpy.distutils,但到目前为止都失败了:
使用 setuptools,
我可以使用 setuptools 编译我的 cython 扩展(并为包的其余部分创建安装)。但是,我无法弄清楚如何使用 setuptools 生成 f2py 扩展。经过广泛的搜索,我只发现了相当旧的像这样的消息,其中指出f2py 模块必须使用 numpy.distutils 进行编译。
使用 numpy.distutils
我可以使用 numpy.distutils 编译我的 f2py 扩展(并为包的其余部分创建安装)。然而,我无法弄清楚如何让 numpy.distutils 编译我的 cython 扩展,因为它最近总是尝试使用 Pyrex 来编译它(并且我正在使用特定于 cython 的扩展)。我已经进行了搜索以找出如何获取 cython 文件的 numpy.distutils 并且 - 至少一年前 - 他们建议应用 numpy.distutils 的猴子补丁。似乎应用这样的猴子补丁也限制了可以传递给 Cython 的选项。
我的问题是:为依赖 f2py 和 cython 的包编写 setup.py 脚本的推荐方法是什么?对 numpy.distutils 应用补丁真的是正确的方法吗?
I would like to create a setup.py script for a python package with several submodules that depend on both cython and f2py. I have attempted to use setuptools and numpy.distutils, but have so far failed:
Using setuptools
I am able to compile my cython extensions (and create an installation for the rest of the package) using setuptools. I have, however, been unable to figure out how to use setuptools to generate the f2py extension. After extensive searching, I only found rather old messages like this one that state that f2py modules must be compiled using numpy.distutils.
Using numpy.distutils
I am able to compile my f2py extensions (and create an installation for the rest of the package) using numpy.distutils. I have, however, been unable to figure out how to get numpy.distutils to compile my cython extensions as it always attempts to use pyrex to compile it (and I am using extensions specific to cython) recent. I have done a search to figure out how to get numpy.distutils for cython files and - at least as of a year ago - they recommend applying a monkey patch to numpy.distutils. It seems applying such a monkey patch also restricts the options that can be passed to Cython.
My question is: what is the recommended way to write a setup.py script for packages that depend on both f2py and cython? Is applying a patch to numpy.distutils really the way to go still?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 setup.py 中单独调用每个函数,如下所示
http://answerpot.com/showthread.php?601643-cython%20and%20f2py
你的调用上下文(我认为他们调用这个命名空间,不确定)
必须更改当前对象的扩展名和功能
setup() 是。
第一个 setup() 调用是 distutils.extension.Extension
和 distutils.core.setup()
第二个 setup() 调用,它是 numpy.distutils.core.Extension
和 numpy.distutils.core.setup()
You can just call each separately in your setup.py as in
http://answerpot.com/showthread.php?601643-cython%20and%20f2py
Your calling context (I think they call this namespace, not sure)
has to change as to what the current object Extension and function
setup() is.
The first setup() call, it's the distutils.extension.Extension
and distutils.core.setup()
The second setup() call, it's the numpy.distutils.core.Extension
and numpy.distutils.core.setup()
事实证明这不再是真的。使用 setuptools 和 distutils(至少是 numpy 版本),可以使用 C、Cython 和 f2py 进行扩展。唯一需要注意的是,要编译 f2py 模块,必须始终对
setup
和Extension
函数使用numpy.distutils
。但是 setuptools 仍然可以用于安装(例如,允许使用 python setup.pydevelop 安装开发人员版本)。要专门使用
distutils
,请使用以下命令:要使用
setuptools
,您需要在distutils
导入之前导入它:然后是其余的代码是相同的:
显然,您需要将所有其他内容放入
setup()
调用中。在上面,我假设您将 numpy 与 Cython 一起使用,以及位于my_c_dir/
的外部 C 文件 (my_ext_c_file.c
),并且 < code>f2py 模块只是一个 Fortran 文件。根据需要进行调整。Turns out this is no longer true. With both
setuptools
anddistutils
(at least thenumpy
version) it is possible to have extensions with C, Cython and f2py. The only caveat is that to compile f2py modules one must always usenumpy.distutils
for both thesetup
andExtension
functions. Butsetuptools
can still be used for the installation (for example, allowing the installation of a developer version withpython setup.py develop
).To use
distutils
exclusively you use the following:To use
setuptools
, you need to import it before thedistutils
imports:And then the rest of the code is identical:
Obviously you need to put all your other stuff in the
setup()
call. In the above I assume that you'll use numpy with Cython, along with an external C file (my_ext_c_file.c
) that will be atmy_c_dir/
, and that thef2py
module is only one Fortran file. Adjust as needed.