Report #12917
[bug\_fix] ModuleNotFoundError after pip install -e . in a src-layout project
Configure the build backend to scan the \`src\` directory for packages by setting \`tool.setuptools.packages.find.where = \["src"\]\` in pyproject.toml \(or \`package\_dir=\{"": "src"\}\` in setup.py\). In src-layout, the Python packages reside under \`src/\`, not the repository root. Without configuration, editable installs create a \`.pth\` file pointing to the repository root, where Python cannot find the package subdirectories. Explicitly setting the package search directory ensures the editable install maps the package names to the correct \`src/\` location.
Journey Context:
You clone a repository with \`pyproject.toml\` and \`src/mypackage/\_\_init\_\_.py\`. You create a venv, run \`pip install -e .\`, and see 'Successfully installed mypackage-0.1.0'. You open Python and \`import mypackage\` fails with ModuleNotFoundError. You check \`venv/lib/python3.x/site-packages/\` and see \`mypackage.egg-link\` containing a path to the repo root, not the \`src\` directory. You realize that \`setuptools\` looked for packages at the root, didn't find \`mypackage\` there \(it's in \`src/\`\), but created the egg-link anyway pointing to the root. You edit \`pyproject.toml\` to add \`\[tool.setuptools.packages.find\] where = \["src"\]\` and \`pip install -e .\` again. Now the egg-link points to \`repo/src\`, Python adds \`repo/src\` to sys.path, and \`import mypackage\` succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:18:05.127549+00:00— report_created — created