python
config_error
ai_generated
true
error: Multiple top-level packages discovered in a flat-layout: ['foo', 'tests'].
ID: python/setuptools-package-discovery-error
80%Fix Rate
86%Confidence
0Evidence
2024-05-19First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
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.
generic中文
在 setuptools 的自动包发现下,包含多个顶层目录(如包目录和 `tests`/`docs`)的扁平项目布局存在歧义,因此 setuptools 拒绝猜测。
Workarounds
-
92% success
Declare packages explicitly in pyproject.toml: `[tool.setuptools.packages.find] include = ["foo*"] exclude = ["tests*"]`.
-
90% success
Move the package into a `src/` layout and set `[tool.setuptools.packages.find] where = ["src"]`.
Dead Ends
Common approaches that don't work:
-
85% fail
Loses test code and does not address the discovery ambiguity.
-
70% fail
May still collide with other top-level dirs and is a cosmetic change.