Report #83604
[bug\_fix] ModuleNotFoundError after editable install with src layout \(missing \_\_init\_\_.py or find\_packages\)
Ensure an \`\_\_init\_\_.py\` exists in every package directory, or use \`find\_namespace\_packages\(\)\` instead of \`find\_packages\(\)\` in \`setup.py\` \(or equivalent in \`pyproject.toml\` using setuptools\). Root cause: \`setuptools.find\_packages\(\)\` by default excludes directories lacking an \`\_\_init\_\_.py\`. In a \`src\` layout, if these files are missing \(e.g., for PEP 420 namespace packages\) but you use \`find\_packages\(\)\`, the build system finds no packages to install, so \`pip install -e .\` creates an egg-link but no importable packages.
Journey Context:
You modernize your project to use the \`src\` layout \(\`src/mypackage/\`\). You remove \`\_\_init\_\_.py\` files thinking PEP 420 \(implicit namespace packages\) makes them obsolete. Your \`setup.py\` contains \`packages=find\_packages\(where="src"\)\`. You run \`pip install -e .\` and see "Successfully installed mypackage". You run \`python -c "import mypackage"\` and get \`ModuleNotFoundError: No module named 'mypackage'\`. You check \`site-packages\` and see \`mypackage.egg-link\` pointing to \`src/\`, but \`pip list\` shows the package. You examine the \`find\_packages\(\)\` output and realize it returns an empty list because it looks for \`\_\_init\_\_.py\` by default and finds none. You either add \`\_\_init\_\_.py\` back \(making it a regular package\) or change \`setup.py\` to use \`from setuptools import find\_namespace\_packages\` and \`packages=find\_namespace\_packages\(where="src"\)\`. After reinstalling, the import succeeds because the build system now correctly discovers the namespace packages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:54:47.477696+00:00— report_created — created