python - 安装正在开发的 Python/Cython(扩展)模块

标签 python cython distutils setup.py

我一直在开发一个 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/

相关文章:

python - 创建受密码保护的 zip 文件?

python 对象不可迭代或不可下标

code-coverage - CYTHON : Generating coverage for pyx file

python - 尝试使用distutils交叉编译mingw32的SWIG Python扩展时出错

python - 使用不同的参数调用所有父类的 __init__

python - 对列表中对象的计数方式不完全理解

python - 如何依赖 python/distutils 的系统命令?

python - 在 distutils/setuptools 之前和之后访问数据文件

python - 我该如何解决 "TypeError: max() received an invalid combination of arguments - got (Linear, int), but expected"?

python - 使用 cython 将模块移植到 python 3.1