Report #36
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' when importing a local directory
Add an empty \`\_\_init\_\_.py\` inside the directory to make it a regular package, or install the project in editable mode \(\`python -m pip install -e .\`\) so the package is on \`sys.path\`. Run imports from the project root.
Journey Context:
You clone a repo with \`src/mypackage/\` and run \`python src/main.py\`, only to see \`ModuleNotFoundError: No module named 'mypackage'\`. You verify the folder exists, then check \`pip list\` and notice the package is not installed. Setting \`PYTHONPATH=src\` makes the import work, proving the directory is simply not on \`sys.path\`. The real cause is that Python only treats directories as packages when they contain \`\_\_init\_\_.py\` \(regular package\) or are explicitly installed. Adding \`\_\_init\_\_.py\` \(or using an editable install\) makes Python recognize the directory as a package and resolves the import.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-11T22:23:11.571710+00:00— report_created — created