Report #7257
[bug\_fix] ModuleNotFoundError after pip install -e . in src-layout project
Configure \`package\_dir\` and \`packages\` \(or \`package-dir\` in pyproject.toml\) to point to the \`src\` directory. In \`setup.py\`: \`package\_dir=\{'': 'src'\}\`, \`packages=find\_packages\(where='src'\)\`. The root cause is that setuptools defaults to looking for packages in the project root; without telling it to look in \`src/\`, the editable install creates an empty package link.
Journey Context:
You clone a repo with \`src/mypkg/\_\_init\_\_.py\`. You create a venv, activate it, run \`pip install -e .\`. It succeeds. You run \`python -c 'import mypkg'\` and get \`ModuleNotFoundError\`. You check \`pip list\` and see \`mypkg\` is installed. You inspect \`venv/lib/python3.x/site-packages/mypkg.egg-link\` and it points to the project root, not the \`src\` folder. You search 'src layout pip install editable' and find setuptools docs. You realize \`setup.py\` has \`packages=find\_packages\(\)\` which looks in root, not \`src\`. You modify \`setup.py\` to \`package\_dir=\{'': 'src'\}\` and \`find\_packages\(where='src'\)\`. You reinstall \`pip install -e .\`. The egg-link now points to \`project-root/src\`, and \`import mypkg\` works because Python finds the package directory under \`src\` via the updated path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:14:22.449077+00:00— report_created — created