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

如何让pyproject.toml的requires-python约束体现在wheel文件名中?

如何让requires-python约束体现在wheel文件名中

默认情况下,纯Python项目构建出的wheel是通用格式(py3-none-any.whl),虽然requires-python元数据会在安装时限制Python版本,但文件名标签不会体现版本约束。要生成带有cp39标签的wheel文件,有两种可行方法:

方法一:构建时指定Python标签参数

执行构建命令时通过--python-tag参数明确指定目标Python版本标签:

pip wheel . --python-tag cp39

执行后即可生成foo-0.0.0-cp39-cp39-any.whl。

方法二:在pyproject.toml中配置固定标签

修改pyproject.toml,添加[tool.setuptools]配置段来指定Python标签:

[build-system]
requires = ["setuptools>=40.8.0", "wheel"]
[project]
name = "foo"
version = "0.0.0"
requires-python = "~=3.9"
[tool.setuptools]
python_tags = ["cp39"]

保存配置后再次执行pip wheel .,就能生成符合要求的wheel文件。

需要注意的是,无论使用哪种方法,requires-python = "~=3.9"的元数据约束依然会生效,安装时pip会自动检查Python版本是否符合要求,文件名标签只是直观体现版本兼容性。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 16:35:23