python
config_error
ai_generated
true
错误:包目录 'src/mypkg' 不存在
error: package directory 'src/mypkg' does not exist
ID: python/setuptools-package-dir-and-packages-conflict
80%修复率
88%置信度
0证据数
2024-06-25首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
setup.py 声明了 packages=['mypkg'] 和 package_dir={'':'src'},但 src/mypkg 目录缺失或命名不同。常见于搭建 src 布局项目时忘记创建包文件夹。
English
setup.py declares packages=['mypkg'] and package_dir={'':'src'} but the src/mypkg directory is missing or named differently. Common when scaffolding a src-layout project and forgetting to create the package folder.
解决方案
-
98% 成功率
mkdir -p src/mypkg && touch src/mypkg/__init__.py
-
95% 成功率
from setuptools import setup, find_packages; setup(packages=find_packages(where='src'), package_dir={'':'src'}) -
92% 成功率
[tool.setuptools.packages.find]\nwhere = ["src"]
无效尝试
常见但无效的做法:
-
90% 失败
Build isolation is not the issue; the source tree is malformed.
-
70% 失败
find_packages() defaults to where='.' and will not find packages under src/.