Cythonize python 模块到不同的目标目录
Cythonize python modules to a different target directory
我正在尝试对一些 python 模块(在 windows 上)进行 cythonize,并希望将生成的 .c 文件存储在不同的目录中。
我试过这样的事情:
from Cython.Build import cythonize
module_list = cythonize(r'C:\myproject\module.py',
force=True,
build_dir=r'C:\myproject\compiled_modules')
编译已完成,但文件 module.c 是在 C:\myproject 中创建的,而不是按预期在 C:\myproject\compiled_modules 中创建的。我做错了什么?
我不确定 cythonize
函数是否可以强制执行此操作。我只会使用命令行:
/path/to/cython yourmod.py -o compiled_modules/yourmod.c
编辑:
可以使用子进程模块从 python 脚本调用此命令:
import subprocess
subprocess.check_call(["/path/to/cython", "yourmod.py", "-o", "compiled_modules/yourmod.c"])
编辑 2:
根据 this Sage developer,cython 不支持重定位 c/cpp 文件,因此看起来要么从命令行编译,要么使用正常配置,然后移动 c/cpp 文件是您唯一的选择。
我正在尝试对一些 python 模块(在 windows 上)进行 cythonize,并希望将生成的 .c 文件存储在不同的目录中。
我试过这样的事情:
from Cython.Build import cythonize
module_list = cythonize(r'C:\myproject\module.py',
force=True,
build_dir=r'C:\myproject\compiled_modules')
编译已完成,但文件 module.c 是在 C:\myproject 中创建的,而不是按预期在 C:\myproject\compiled_modules 中创建的。我做错了什么?
我不确定 cythonize
函数是否可以强制执行此操作。我只会使用命令行:
/path/to/cython yourmod.py -o compiled_modules/yourmod.c
编辑:
可以使用子进程模块从 python 脚本调用此命令:
import subprocess
subprocess.check_call(["/path/to/cython", "yourmod.py", "-o", "compiled_modules/yourmod.c"])
编辑 2:
根据 this Sage developer,cython 不支持重定位 c/cpp 文件,因此看起来要么从命令行编译,要么使用正常配置,然后移动 c/cpp 文件是您唯一的选择。