# 错误：在扁平布局中发现了多个顶层包：['foo', 'tests']。

- **ID:** `python/setuptools-package-discovery-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 setuptools 的自动包发现下，包含多个顶层目录（如包目录和 `tests`/`docs`）的扁平项目布局存在歧义，因此 setuptools 拒绝猜测。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (92% 成功率)
   ```
   Declare packages explicitly in pyproject.toml: `[tool.setuptools.packages.find] include = ["foo*"] exclude = ["tests*"]`.
   ```
2. **** (90% 成功率)
   ```
   Move the package into a `src/` layout and set `[tool.setuptools.packages.find] where = ["src"]`.
   ```

## 无效尝试

- **** — Loses test code and does not address the discovery ambiguity. (85% 失败率)
- **** — May still collide with other top-level dirs and is a cosmetic change. (70% 失败率)
