【问题标题】:How to build multiple Cython files into one python extension [duplicate]如何将多个 Cython 文件构建到一个 python 扩展中[重复]
【发布时间】:2018-06-21 11:56:15
【问题描述】:

目前我有一个 pyx 文件包含所有类(父类和子类)。现在我想把它分解成多个文件,父类一个文件,每个子类都有自己的文件。 所以有两件事我想知道

  1. 如何在子类文件中导入父类?
  2. 为了构建扩展需要在 setup.py 中进行哪些更改?

setup.py 看起来像

from distutils.core import setup

from Cython.Build import cythonize

setup(ext_modules = cythonize("MyLibrary.pyx"))

我已经 google 了它,但我得到的是如何一次构建多个扩展。感谢提前

【问题讨论】:

    标签: python cython


    【解决方案1】:

    事实证明这很容易。我什至不需要更改 setup.py 我只是将子类的代码移动到他们自己的文件中,并从父类中包含它们。

    会变成这样的

    • Child1.pyx
    • Child2.pyx
    • Child3.pyx
    • MyLibrary.pyx

    MyLibrary.pyx

    .
    .
    .
    include Child1.pyx
    include Child2.pyx
    include Child3.pyx
    
    class parent:
    .
    .
    .
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-04
      • 2023-01-15
      • 2012-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多