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

如何生成符合PyPI规范的完整Wheel文件名?

问题分析与解决方案

你的元数据存在两处关键问题,导致生成了通用型Wheel文件,无需更换Poetry、Flit等工具,调整pyproject.toml配置即可实现目标文件名。

问题1:分类器与平台配置冲突

你在classifiers中添加了Operating System :: OS Independent,这会让Hatchling认为你的项目是跨平台的,直接生成any平台的Wheel。需要删除该分类器,替换为对应macOS的分类器:

classifiers = [
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS :: MacOS X",
]

问题2:缺少Hatchling的Wheel标签配置

默认情况下,纯Python项目会生成py3-none-any.whl,要生成指定Python版本和平台的Wheel,需要在pyproject.toml中添加Hatchling的Wheel构建配置,明确指定目标标签:

[tool.hatch.build.targets.wheel]
tags = ["cp310-cp310-macosx_10_9_x86_64"]

如果希望自动适配当前构建环境的Python版本和平台(而非硬编码),可以改用动态标签生成逻辑:

[tool.hatch.build.targets.wheel]
pure = false

注:pure = false会强制Hatchling生成平台相关的Wheel,即使你的项目是纯Python代码,它会自动读取当前环境的Python版本和系统平台生成对应标签。

调整后的完整pyproject.toml示例

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "cleanmysurface"
version = "0.0.3"
authors = [
{ name="blabla", email="blabla@icloud.com" },
]
description = "A melange package to calculate your mixture to clean surfaces"
readme = "README.md"
requires-python = ">=3.10"
platform = "macosx_10_9_x86_64"

classifiers = [
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS :: MacOS X",
]

[project.urls]
"Homepage" = "https://github.com/blabla/melange"
"Bug Tracker" = "https://github.com/blabla/melange/issues"

[tool.hatch.build.targets.wheel]
tags = ["cp310-cp310-macosx_10_9_x86_64"]

执行python -m build后,就能生成你期望的cleanmysurface-0.0.3-cp310-cp310-macosx_10_9_x86_64.whl文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 20:35:26