Report #5669
[bug\_fix] ModuleNotFoundError for namespace package due to local directory shadowing \(PEP 420\)
Remove or rename the empty local directory \(e.g., \`google/\`, \`azure/\`, or \`tests/\`\) that lacks an \`\_\_init\_\_.py\` but matches the namespace package name, ensuring the installed site-packages version is found first in \`sys.path\`. Root cause: PEP 420 defines implicit namespace packages \(directories without \`\_\_init\_\_.py\`\). If the current working directory contains a folder named \`google\`, Python treats it as a namespace package and stops searching, preventing discovery of the installed \`google\` namespace containing \`google.cloud\` subpackages.
Journey Context:
Developer installs \`google-cloud-storage\` via pip. They create a local folder named \`google\` to store some unrelated internal scripts, but forget to add an \`\_\_init\_\_.py\`. Later, running \`python -c "from google.cloud import storage"\` raises \`ModuleNotFoundError: No module named 'google.cloud'\`. The developer verifies \`pip show google-cloud-storage\` shows it installed in site-packages. They check \`sys.path\` and see \`''\` \(current dir\) is first. They notice their local \`google/\` folder exists. Realizing Python 3 treats this as an implicit namespace package per PEP 420, they understand it shadows the installed \`google\` namespace. Renaming the local folder to \`google\_utils/\` removes the shadow, allowing the import system to find the site-packages \`google\` namespace package.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:51:04.462306+00:00— report_created — created