Report #68415
[bug\_fix] Namespace package collision causing partial import or shadowing \(ImportError/ModuleNotFoundError for subpackage\)
Ensure the namespace directory \(e.g., 'google/'\) contains no \_\_init\_\_.py \(PEP 420 implicit namespace\), or if using pkg\_resources namespaces, ensure all participating packages use the same namespace technique \(pkgutil.extend\_path or declare\_namespace\) and no stray \_\_init\_\_.py exists.
Journey Context:
You have two packages installed: 'google-cloud-storage' and 'google-cloud-pubsub'. Both provide the 'google.cloud' namespace. You run 'from google.cloud import storage' and it works, but 'from google.cloud import pubsub' raises 'ModuleNotFoundError: No module named 'google.cloud.pubsub'' despite pip showing both installed. You check 'google/\_\_init\_\_.py' and find it contains 'pkgutil.extend\_path' or 'declare\_namespace', but one of the packages \(maybe an older version\) installed a regular \_\_init\_\_.py that shadows the other. The issue is that PEP 420 allows implicit namespace packages \(directories without \_\_init\_\_.py\), but if any installed package puts an \_\_init\_\_.py in the namespace root \(google/\_\_init\_\_.py\), Python treats it as a regular package and stops searching for other portions of the namespace in other directories on sys.path. The fix is to remove all \_\_init\_\_.py files from namespace package directories \(letting PEP 420 handle it implicitly\) or ensure all packages sharing the namespace use the exact same legacy namespace technique consistently.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:19:08.463216+00:00— report_created — created