You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cython化PyPI包后,Tox测试无法验证编译状态的问题

问题:Cython化PyPI包后,tox测试无法验证编译状态

我正在开发一个基于Python文件的PyPI包,使用tox进行测试。为提升性能,尝试对该包进行Cython化,同时希望通过tox验证包是否已完成编译。

已完成的配置调整

  • 修改setup.py,添加Cython相关配置
import pathlib

from setuptools import setup
from Cython.Build import cythonize

setup(
    install_requires=[
        "Cython>=0.29.21" # <-- 新增配置
    ],
    ext_modules=cythonize("mypackage_name/*.py"), # <-- 新增配置
)
  • 创建pyproject.toml文件
[build-system]
requires = ["setuptools", "wheel", "Cython>=0.29.21"]
build-backend = "setuptools.build_meta"
  • 修改tox.ini,开启隔离构建
[tox]
envlist = py{310, 311}
isolated_build = true ; <-- 新增配置

[testenv]
deps =
    -rrequirements.txt
commands =
    python -m pytest tests -s

验证尝试

为测试Cython是否生效,在包的Python文件中添加了以下判断函数:

def compiled() -> bool:
    import Cython
    return Cython.compiled

编写pytest测试并通过tox执行,但测试结果始终显示包未被编译。

内容的提问来源于stack exchange,提问作者CodingTil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 17:45:44