python config_error ai_generated true

错误:在扁平布局中发现了多个顶级包:['pkg1', 'pkg2']。

error: Multiple top-level packages discovered in a flat-layout: ['pkg1', 'pkg2'].

ID: python/setuptools-find-packages-no-init

其他格式: JSON · Markdown 中文 · English
80%修复率
84%置信度
0证据数
2024-06-01首次发现

版本兼容性

版本状态引入弃用备注
3.8 active
3.9 active
3.10 active
3.11 active

根因分析

使用find_packages()而未指定where时,setuptools检测到当前目录中的多个顶级包,这是不明确的,不允许。

English

When using find_packages() without specifying where, setuptools detects multiple top-level packages in the current directory, which is ambiguous and not allowed.

generic

解决方案

  1. 90% 成功率
    Specify the source directory: `packages=find_packages(where='src')` and move packages to src/ layout.
  2. 95% 成功率
    Explicitly list packages: `packages=['pkg1', 'pkg2']` in setup.py.
  3. 80% 成功率
    Use `find_namespace_packages()` for namespace packages if applicable.

无效尝试

常见但无效的做法:

  1. 40% 失败

    This is not practical if both packages are needed; and the error is about configuration, not about having multiple packages.

  2. 90% 失败

    This will cause no packages to be installed, defeating the purpose.

  3. 50% 失败

    This still leaves pkg2 undiscovered and may not include all needed modules.