# 错误：setuptools.errors.PackageDiscoveryError：在扁平布局中发现多个顶级包：['mypackage', 'mypackage2']

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

## 根因

Setuptools 自动发现功能在根目录中找到多个包，导致歧义。

## 版本兼容性

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

## 解决方案

1. **Explicitly specify packages in setup.cfg or setup.py** (95% 成功率)
   ```
   In setup.cfg: [options]
packages = find:
find:
include = mypackage*
Or in setup.py: packages=['mypackage']
   ```
2. **Use namespace packages if both are related** (85% 成功率)
   ```
   Rename packages to share a namespace like 'company.mypackage' and 'company.mypackage2'.
   ```

## 无效尝试

- **Renaming one package to a subpackage** — Does not resolve the discovery conflict; setuptools still sees two top-level packages. (70% 失败率)
- **Removing one package directory entirely** — Loss of code; better to configure explicitly. (50% 失败率)
