【问题标题】:How do include cython files in python meson-managed project?如何在 python 介子管理的项目中包含 cython 文件?
【发布时间】:2021-06-14 06:28:32
【问题描述】:

如何在介子构建系统管理的 python 介子项目中正确包含 cython 源文件?

【问题讨论】:

    标签: python cython meson-build


    【解决方案1】:

    Cython 作为一等语言是still in progress(我是该作品的作者),现在正确的方法是使用生成器或自定义目标,然后编译扩展模块:

    pyx_c = custom_target(
      'cython_file.c',
      output : 'cython_file.c',
      input : 'cython_file.pyx',
      command : [cython, '@INPUT@', '-o', '@OUTPUT@'],
    )
    
    import('python').find_installation().extension_module(
      'my_extension_module'
      pyx_c,
      install : true
    )
    

    Here's an example from the meson test suite,这与我上面的示例非常接近。

    编辑:cython 作为一流的语言已经登陆。所以如果你可以依赖 Meson 0.59.0,你可以这样做:

    import('python').find_installation().extension_module(
      'my_extension_module'
      'cython_file.pyx',
      install : true
    )
    

    【讨论】:

      【解决方案2】:

      我发现的最简单的方法(完全是代码端)是像任何其他源文件一样添加它们,并且当您需要将它们导入到 python 文件中时

      添加

      from pyximport import install
      install(language_level=3)
      

      在导入之前。

      最好的方法 是 @dcbaker 的。我编写了一个示例 pygobject cython 应用程序来显示 here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-16
        • 2013-03-17
        • 2017-12-31
        • 1970-01-01
        • 2017-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多