Report #75895
[bug\_fix] ModuleNotFoundError after 'pip install -e .' with src-layout project
Configure setuptools with 'package\_dir=\{"": "src"\}' and 'packages=find\_packages\(where="src"\)' in setup.py, or use a modern backend like hatchling/hatch which handles src-layout natively without extra configuration.
Journey Context:
A developer restructures their project to use the 'src-layout' \(src/mypackage/\_\_init\_\_.py\) recommended by packaging.python.org. They run 'pip install -e .' which reports success. However, when they open Python and 'import mypackage', they get 'ModuleNotFoundError'. Investigating site-packages, they find an .egg-link file pointing to their project root, not the src/ directory. They realize that the editable install linked the root directory, but Python cannot find 'mypackage' because it's inside src/, not at the root. The fix requires telling setuptools to map the package root to the src directory using 'package\_dir=\{"": "src"\}' and telling find\_packages to look there with 'where="src"'. After updating setup.py and reinstalling, the .egg-link correctly allows importing the package.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:58:50.768850+00:00— report_created — created