python module_error ai_generated partial

ImportError: cannot import name 'foo' from partially initialized module 'mypkg' (most likely due to a circular import)

ID: python/setuptools-namespace-package-conflict

Also available as: JSON · Markdown · 中文
80%Fix Rate
82%Confidence
0Evidence
2025-08-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.9 active
3.10 active
3.11 active

Root Cause

Namespace package layout misconfigured via setup.py/pyproject.toml, causing circular or partial imports.

generic

中文

通过 setup.py/pyproject.toml 配置的命名空间包布局错误,导致循环或部分导入。

Workarounds

  1. 85% success
    from setuptools import setup, find_namespace_packages
    setup(name='mypkg', packages=find_namespace_packages(include=['mypkg.*']))
  2. 90% success
    [tool.setuptools.packages.find]
    namespaces = true
    include = ["mypkg*"]

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Breaks the intended namespace-package semantics and can cause duplicate module paths.

  2. 60% fail

    Masks the layout issue; import may still fail elsewhere.