Report #94286
[bug\_fix] ImportError: cannot import name 'X' from 'namespace' or pkg\_resources.DistributionNotFound for namespace packages
Ensure all packages sharing the namespace use the same namespace package mechanism. Remove \`\_\_init\_\_.py\` from the namespace directory to use PEP 420 implicit namespace packages \(modern\), or ensure all use \`pkgutil.extend\_path\` consistently \(legacy\). Do not mix PEP 420 and pkgutil namespaces.
Journey Context:
Developer works on a project using \`google-cloud-storage\` and an internal legacy library \`google-internal\`. \`google-cloud-storage\` uses PEP 420 implicit namespace \(no \`\_\_init\_\_.py\` in \`google/\`\). The internal library was built with old setuptools \`namespace\_packages=\['google'\]\` which creates an \`\_\_init\_\_.py\` using \`pkgutil.extend\_path\`. When both are installed, Python sees the \`\_\_init\_\_.py\` from the legacy package first, treating \`google\` as a regular package, shadowing the namespace package portion from \`google-cloud-storage\`. Imports for \`google.cloud\` fail with ModuleNotFoundError. Developer debugs \`import google; print\(google.\_\_path\_\_\)\` and sees only one path to the internal package. Realizing the collision, they update the internal package to use PEP 420 by removing \`namespace\_packages\` from setup.py and deleting \`google/\_\_init\_\_.py\` from the source, resolving the conflict.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:50:46.040333+00:00— report_created — created