用cython为一组文件制作一个pyd [英] making one pyd for a set of files with cython

查看:418
本文介绍了用cython为一组文件制作一个pyd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个包中有多个.py文件

I have multiple .py files in one package

packageA
    \__init__.py
    \mod1.py
    \mod2.py
    \mod3.py

我可以配置cython进行编译,然后将它们全部打包到一个 packageA.pyd 吗?

can I config cython to compile and then packing them all in one packageA.pyd ?

推荐答案

我个人最好将所有 .py 文件转换为 .pyx ,然后包括将它们放入Cython扩展名的主 .pyx 中:

Personally, I would better turn all the .py files into .pyx, then include them into the main .pyx of the Cython extension:

packageA.pyx

include "mod1.pyx" 
include "mod2.pyx" 
include "mod3.pyx" 

然后,使用 setup.py 看起来像这样:

Then, compile using a setup.py looking like:

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

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [
        Extension("packageA", sources=["packageA.pyx"])
    ]
)                       

正在运行这将生成一个完整的 packageA.pyd 二进制文件。
当然,这将输出一个名为 packageA 的模块,我不知道这是否适合您,或者您是否真的需要在其中使用不同的模块您的包裹。
但是可能还有其他方法可以更好地满足您的问题...

Running this would generate an all in one packageA.pyd binary file. Of course, this will output a single module named packageA, and I don't know if this is acceptable for you, or if you really need distinct modules in your package. But there might be other ways that better fit your question...

这篇关于用cython为一组文件制作一个pyd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆