代码之家  ›  专栏  ›  技术社区  ›  uday

如何在cython中编译多个文件

  •  5
  • uday  · 技术社区  · 9 年前

    新来的Cython。我在名为 setup.py 将另一个文件编译为 Cython (这是一位SO用户通过 here ):

    from distutils.core import setup
    from distutils.extension import Extension
    from Cython.Distutils import build_ext
    
    ext_modules = [Extension('func1', ['util/func1_pc.py'],)]
    
    setup(
        name="Set 1 of Functions",
        cmdclass={'build_ext': build_ext},
        ext_modules=ext_modules
    )
    

    我将其编译为 python setup.py build_ext --inplace 。这将在以下位置编译我的文件 util/func1_pc.py 进入 func1.pyd 在的目录中 设置.py .

    假设我现在有两个文件: util/funct1_pc.py util/funct2_pc.py 。是否可能有人建议如何修改上述代码段以生成 函数1.pyd func2.pyd 从他们身上?

    谢谢

    2 回复  |  直到 4 年前
        1
  •  3
  •   Liam Marshall    9 年前

    这个 Extension constructor 允许您指定多个源文件,因此更改 ext_modules 行到此:

    ext_modules = [Extension('func1', ['util/func1_pc.py', 'util/funct2_pc.py'],)]
    

    应该会成功。

        2
  •  1
  •   Alex Pashkov    3 年前

    run_cython.pyx-与setup.py的目录位于同一级别的文件

    compiled.pyx-来自目录的文件,与setup.py的目录位于同一级别

    from distutils.core import setup
    from Cython.Build import cythonize
    
    setup(ext_modules = cythonize(
        'run_cython.pyx',
        './app/compilled.pyx'
    )
    )