python config_error ai_generated true

error: Multiple top-level packages discovered in a flat-layout: ['src', 'tests', 'docs'].

ID: python/setuptools-discovery-multiple-top-level

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

Setuptools auto-discovery in a flat layout finds more than one candidate package directory and refuses to guess which is the real one.

generic

中文

Setuptools 在扁平布局中的自动发现找到多个候选包目录,拒绝猜测哪一个是真正的包。

Workarounds

  1. 97% success
    [tool.setuptools]
    packages = ["mypkg"]
    # or
    [tool.setuptools.packages.find]
    where = ["src"]
    include = ["mypkg*"]
  2. 95% success
    # move mypkg/ to src/mypkg/
    [tool.setuptools.packages.find]
    where = ["src"]

Dead Ends

Common approaches that don't work:

  1. 85% fail

    MANIFEST.in controls sdist contents, not setuptools package discovery.

  2. 90% fail

    The discovery error occurs during build regardless of isolation.

  3. 70% fail

    Discovery still finds src/ and _tests/ as candidates.