我一直在开发一个 Python 模块,其中包含用 Cython 包装的 C++ 扩展。 setup.py
当前处理扩展模块的构建,并被称为 python3 setup.py --build_ext --inplace
。
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
srcDir = "../src"
src = ["_MyProject.pyx"] # list of source files
print("source files: {0}".format(src))
modules = [Extension("_MyProject",
src,
language = "c++",
extra_compile_args=["-fopenmp", "-std=c++11", "-O3", "-DNOGTEST"],
extra_link_args=["-fopenmp", "-std=c++11"],
libraries=["MyProjectLib", "log4cxx"],
library_dirs=["../"])]
for e in modules:
e.cython_directives = {"embedsignature" : True}
setup(name="_MyProject",
cmdclass={"build_ext": build_ext},
ext_modules=modules)
在 Cython 模块 _MyProject
之上,有一个纯 Python 模块 MyProject
,它从 _MyProject
导入内容。
目前,我通过 cd
-ing 进入其目录并从那里导入它来使用和测试该模块。我需要如何修改 setup.py
以便将 MyProject
安装到我的站点包中并让该包始终保持最新?
最佳答案
将参数 py_modules = ["MyProject.py",]
添加到 setup() 函数中。
关于python - 安装正在开发的 Python/Cython(扩展)模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20457007/