InvalidDistribution: Invalid distribution metadata: unrecognized or malformed field 'license-file'
简介
执行 twine upload dist/* 命令上传项目到PyPI出现报错
# twine upload dist/*
Uploading distributions to https://upload.pypi.org/legacy/
ERROR InvalidDistribution: Invalid distribution metadata: unrecognized or malformed field 'license-file'
问题分析:
一开始怀疑 pyproject.toml 格式写的不对,检查后发现并没有。搜索后发现是 twine的不兼容 Bug,原因是使用了较新的 Twine,但配合的是一个稍旧的 packaging 库,以及一个生成了无效元数据的构建后端。
虽然 Twine 本身有处理这类无效元数据的机制,但这个机制只有在新版 packaging 库中才会生效。Bug号 https://github.com/pypa/twine/issues/1216
解决方案:
# 升级packaging
pip install -U packaging

浙公网安备 33010602011771号