python
config_error
ai_generated
true
错误:在扁平布局中发现多个顶级包:['src', 'tests', 'docs']。
error: Multiple top-level packages discovered in a flat-layout: ['src', 'tests', 'docs'].
ID: python/setuptools-package-discovery-flat-layout
80%修复率
88%置信度
0证据数
2024-02-27首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
当多个同级目录看起来像包时,setuptools 自动发现拒绝猜测哪个顶级目录是真正的包;需要显式配置。
English
setuptools auto-discovery refuses to guess which top-level directory is the real package when several sibling directories look like packages; explicit configuration is required.
解决方案
-
97% 成功率
[tool.setuptools.packages.find] where = ["src"] include = ["mypkg*"] # or list them [tool.setuptools] packages = ["mypkg"]
-
94% 成功率
mkdir -p src/mypkg mv mypkg/* src/mypkg/ touch src/mypkg/__init__.py # then configure [tool.setuptools.packages.find] where = ["src"]
无效尝试
常见但无效的做法:
-
60% 失败
Works around the symptom but breaks conventional tooling and CI that expect those names.
-
80% 失败
Makes the ambiguity worse; setuptools now sees even more candidate packages.