指定cython输出文件 [英] Specify cython output file
问题描述
似乎默认情况下,从distutils.core中将cmdclass设置为build_ext的安装程序编译当前工作目录中的cpp或c文件。有没有一种方法可以确定将生成的c代码写入何处?否则,存储库中会堆满生成的代码。
It seems that by default setup from distutils.core with cmdclass set to build_ext, compiles a cpp or c file in the current working directory. Is there a way to determine where the generated c code is written to? Otherwise, a repository will be littered with generated code.
例如,此文件setup.py会将文件example.c写入当前工作目录:
For example this file setup.py will write a file example.c to the current working directory:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("example.pyx"))
推荐答案
您可以将选项 build_dir =目录名称
传递给 Cythonize
# rest of file as before
setup(
ext_modules = cythonize("example.pyx",
build_dir="build"))
上面的代码会将生成的c文件放在目录 build中(这很有意义,因为
The above code will put the generated c files in the directory "build" (which makes sense, since by default it's where distutils puts temporary object files and so forth when it's building).
我的原始答案是工作
,而不是 build_dir
。感谢@ArthurTacca指出这似乎不再正确。
My original answer had working
, not build_dir
. Thanks to @ArthurTacca for pointing out that that no longer seems to be right.
这篇关于指定cython输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!