【问题标题】:What happens with "pure" Python + Cython packages during installation built failure?在安装构建失败期间,“纯”Python + Cython 包会发生什么?
【发布时间】:2020-02-17 19:14:32
【问题描述】:

我刚刚阅读了Cython Pure Python Mode documentation,但我不确定我是否理解正确。听起来好像我可以保持所有 Python 文件原样,在我声明 Cython 类型的地方添加 *.pxd 文件。在setup.py中,我还是加了

from setuptools import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize(
        "A.py",
        compiler_directives={'language_level' : "3"}
      )
)

当我运行 python setup.py build_ext --inplace 时,它实际上会构建 .so 文件。

当我创建 sdist / bdist,将它们上传到 PyPI 并且用户没有匹配的平台时会发生什么?他们肯定会下载 sdist。我猜 pip / setuptools 会自动尝试编译扩展模块(A.py),我猜如果它有效,那很好。但是如果 cythonize 失败了怎么办?它还会安装包并使用纯 Python 代码吗?

【问题讨论】:

    标签: pip cython setuptools


    【解决方案1】:

    我不这么认为。我相信setup.py 的失败会完全中止安装。

    您可以尝试declare an extension optional,但reports 并没有真正起作用。可能是旧的setuptools 的问题。

    【讨论】:

    • 嗯 ...然后,我想,可以使用环境变量来添加/不添加扩展名。对于源代码分发,它不会被添加,因此不会被构建。对于轮子,我可以控制环境变量并因此构建它。创建轮子后,设置选项是否设置无关紧要,因为 .so 已经在轮子中。这可能行得通,对吧?
    • 是的,看起来可行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 2020-05-06
    • 2020-09-09
    • 1970-01-01
    • 2020-09-18
    • 2016-11-09
    • 1970-01-01
    相关资源
    最近更新 更多