编译一个 Cython 项目并清理

Compile a Cython project and clean

我正在使用:

from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize("myfile.pyx"))

编译myfile.pyx。有没有办法:

  1. 在当前文件夹中有 .pyd(而不是 build/ 子文件夹)
  2. 编译后清理(即删除build/子文件夹,删除.c文件)

无需自己使用 os.remove(...) ?

您可以使用 --inplace 选项:

--inplace (-i)       ignore build-lib and put compiled extensions into the
                     source directory alongside your pure Python modules

setup.py clean 应该清理构建目录。 setup.py clean --all 清除所有构建输出。