# 错误：包目录 'src/mypkg' 不存在

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

## 根因

setup.py 声明了 packages=['mypkg'] 和 package_dir={'':'src'}，但 src/mypkg 目录缺失或命名不同。常见于搭建 src 布局项目时忘记创建包文件夹。

## 版本兼容性

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

## 解决方案

1. **** (98% 成功率)
   ```
   mkdir -p src/mypkg && touch src/mypkg/__init__.py
   ```
2. **** (95% 成功率)
   ```
   from setuptools import setup, find_packages; setup(packages=find_packages(where='src'), package_dir={'':'src'})
   ```
3. **** (92% 成功率)
   ```
   [tool.setuptools.packages.find]\nwhere = ["src"]
   ```

## 无效尝试

- **** — Build isolation is not the issue; the source tree is malformed. (90% 失败率)
- **** — find_packages() defaults to where='.' and will not find packages under src/. (70% 失败率)
