python
config_error
ai_generated
true
错误:在扁平布局中发现了多个顶层包:['foo', 'tests']。
error: Multiple top-level packages discovered in a flat-layout: ['foo', 'tests'].
ID: python/setuptools-package-discovery-error
80%修复率
86%置信度
0证据数
2024-05-19首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
在 setuptools 的自动包发现下,包含多个顶层目录(如包目录和 `tests`/`docs`)的扁平项目布局存在歧义,因此 setuptools 拒绝猜测。
English
With setuptools' automatic package discovery, a flat project layout containing more than one top-level directory (e.g. the package and a `tests`/`docs` dir) is ambiguous, so setuptools refuses to guess.
解决方案
-
92% 成功率
Declare packages explicitly in pyproject.toml: `[tool.setuptools.packages.find] include = ["foo*"] exclude = ["tests*"]`.
-
90% 成功率
Move the package into a `src/` layout and set `[tool.setuptools.packages.find] where = ["src"]`.
无效尝试
常见但无效的做法:
-
85% 失败
Loses test code and does not address the discovery ambiguity.
-
70% 失败
May still collide with other top-level dirs and is a cosmetic change.