python config_error ai_generated true

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

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2024-06-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active
3.9 active
3.10 active
3.11 active

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 40% fail

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

  2. 90% fail

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

  3. 50% fail

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