Report #70085
[bug\_fix] Implicit namespace package shadowing \(ModuleNotFoundError or wrong module imported\)
Add an empty \`\_\_init\_\_.py\` file to directories that should be regular packages \(not namespace packages\) to prevent Python 3.3\+ implicit namespace logic from causing unintended shadowing, or explicitly reorder \`sys.path\` to ensure the intended package directory is found first.
Journey Context:
Developer has a project structure with \`project/src/pkg/\` and \`other/pkg/submod.py\`. Both directories are on \`sys.path\`. \`project/src/pkg/\` is a regular package with \`\_\_init\_\_.py\`, while \`other/pkg/\` is an implicit namespace package \(no \`\_\_init\_\_.py\`\) containing \`submod.py\`. Developer tries \`from pkg import submod\`. Python scans \`sys.path\`, finds \`project/src/pkg/\` first, recognizes it as a regular package, and stops searching for \`pkg\`. It never sees \`other/pkg/\`, so \`submod\` is not found, raising \`ModuleNotFoundError\`. Developer is confused because \`ls other/pkg/submod.py\` shows the file exists. They try \`sys.path.insert\(0, 'other'\)\` and it works, confirming a path ordering issue. They realize the lack of \`\_\_init\_\_.py\` in \`other/pkg/\` makes it a namespace package, but the regular package in \`project/\` shadows it entirely rather than merging as namespace packages do when both are namespace packages. Adding \`\_\_init\_\_.py\` to \`other/pkg/\` would also fix it by making both regular packages, causing an error or shadowing based on order, but the real fix is ensuring \`\_\_init\_\_.py\` exists where needed or managing \`sys.path\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:13:07.424211+00:00— report_created — created