Report #54980
[bug\_fix] ModuleNotFoundError: No module named 'google.cloud' \(or similar namespace package\) despite package being installed
Remove or rename any local directory or file named \`google.py\` or \`google/\` in the current working directory or script directory that shadows the installed namespace package. The root cause is that Python's import system searches \`sys.path\` left-to-right, and the directory containing the script \(or CWD\) is usually first. If a local \`google/\` folder exists \(even empty\), Python treats it as the \`google\` namespace package and stops searching, preventing it from finding the installed \`google.cloud\` subpackage in site-packages.
Journey Context:
Developer starts a new project. They install \`google-cloud-storage\` using \`pip install google-cloud-storage\`. They create a test file \`test.py\` in their project root. Accidentally, they also have a folder named \`google/\` in the root \(perhaps created earlier for unrelated experiments, containing an empty \`\_\_init\_\_.py\` or just empty\). They write \`from google.cloud import storage\` in \`test.py\`. Running \`python test.py\` raises \`ModuleNotFoundError: No module named 'google.cloud'\`. Confused, they run \`pip list \| grep google\` and see \`google-cloud-storage\` installed. They run \`python -c "import google; print\(google.\_\_file\_\_\)"\` and it prints \`./google/\_\_init\_\_.py\` \(the local empty folder\) instead of the path to the namespace package in site-packages. They realize the local folder shadows the installed namespace package. They delete or rename the local \`google/\` folder. Running \`test.py\` again succeeds, and \`google.\_\_file\_\_\` now points to the namespace package in \`site-packages\`, allowing \`google.cloud\` to be found.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:46:46.366449+00:00— report_created — created