Report #11627
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' after \`pip install -e .\` in a src-layout repository
Add explicit package discovery to pyproject.toml: \`\[tool.setuptools.packages.find\] where = \["src"\]\` and \`package\_dir = \{"": "src"\}\`. The root cause is that setuptools defaults to looking for packages in the repository root; when sources are under \`src/\`, the editable install creates an egg-link pointing to a tree that does not contain the importable package root, so Python cannot locate the module despite the link.
Journey Context:
A developer clones a repository structured with a \`src/mypackage/\` directory containing the code. They create a fresh virtual environment and run \`pip install -e .\` in the repository root. The command succeeds and \`pip list\` shows \`mypackage\` with an egg-link pointing to the current directory. However, when they open a Python REPL and type \`import mypackage\`, they receive \`ModuleNotFoundError\`. They inspect \`python -c "import sys; print\(sys.path\)"\` and see the site-packages directory, but the editable link points to a directory that contains \`src/mypackage\`, not \`mypackage\` directly. They realize that because the source is under \`src/\`, setuptools needs to be told to look there. After adding the \`package\_dir\` and \`packages.find\` configuration to \`pyproject.toml\`, reinstalling the editable package creates a \`.pth\` file or egg-link that correctly adds \`src/\` to \`sys.path\`, allowing imports to resolve.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:48:40.474268+00:00— report_created — created