在 python setuptools 中混合 cython 和 cmake 扩展

问题描述

我有一个带有以下 setup.py 的 python 包:

 ValueError: `decode_predictions` expects a batch of predictions (i.e. a 2D array of shape (samples,1000)). Found array with shape: (1,100352)

我想知道我是否可以调用 from setuptools import setup,Extension from setuptools.command.build_ext import build_ext class CMakeExtension(Extension): # ... class CMakeBuild(build_ext): # ... extensions = [ CMakeExtension("cmake_extension","path-to-sources"),Extension("cython_extension",["file.pyx"]),] setup( # ... ext_modules=extensions,# ... ) 并使用适当的构建器构建每个扩展。

我知道 python setup.py build_ext --inplace 设置函数参数,但没有找到指定 cmdclass 用于 cython 扩展和 build_ext 用于 cmake 扩展的方法。>

请注意,每个扩展都使用正确的构建器类(和 CMakeBuild 参数)构建良好。

谢谢!

解决方法

最好的办法是确保 CMakeBuild 检测到扩展的类型并在扩展不是 build_ext 的实例时恢复到原始 CMakeExtension