【问题标题】:Cython setup.py for several .pyx几个 .pyx 的 Cython setup.py
【发布时间】:2014-03-16 13:48:27
【问题描述】:

我想更快地进行 cythonize。一个 .pyx 的代码是

from distutils.core import setup
from Cython.Build import cythonize

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

如果我想 cythonize 怎么办

  • 几个带有 ext .pyx 的文件,我将用它们的名字来称呼它们

  • 文件夹中的所有 .pyx 文件

在这两种情况下 setup.py 的 python 代码是什么?

【问题讨论】:

    标签: python compilation installation cython setup.py


    【解决方案1】:

    发件人:https://github.com/cython/cython/wiki/enhancements-distutils_preprocessing

    # several files with ext .pyx, that i will call by their name
    from distutils.core import setup
    from distutils.extension import Extension
    from Cython.Distutils import build_ext
    
    ext_modules=[
        Extension("primes",       ["primes.pyx"]),
        Extension("spam",         ["spam.pyx"]),
        ...
    ]
    
    setup(
      name = 'MyProject',
      cmdclass = {'build_ext': build_ext},
      ext_modules = ext_modules,
    )
    


    # all .pyx files in a folder
    from distutils.core import setup
    from Cython.Build import cythonize
    
    setup(
      name = 'MyProject',
      ext_modules = cythonize(["*.pyx"]),
    )
    

    【讨论】:

    • 嘿,如果我想将库和 include_dirs 放入代码中怎么办。 Nad everyname ofr pyx 在同一个。所以我有一个 .so 文件
    【解决方案2】:

    上面的答案对我来说并不完全清楚。要对不同目录中的两个文件进行 cythonize,只需在 cythonize(...) 函数中列出它们即可:

    from distutils.core import setup
    from Cython.Build import cythonize
    
    setup(
        ext_modules = cythonize(["folder1/file1.pyx", "folder2/file2.pyx"])
    )
    

    【讨论】:

      猜你喜欢
      • 2020-06-28
      • 1970-01-01
      • 2015-03-31
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-06
      • 1970-01-01
      相关资源
      最近更新 更多