Report #70080
[bug\_fix] ModuleNotFoundError after \`pip install -e .\` in src-layout project
Configure setuptools to find packages in the \`src\` directory by setting \`package\_dir=\{"": "src"\}\` in \`setup.py\`, or in \`pyproject.toml\` set \`\[tool.setuptools.packages.find\] where = \["src"\]\` so that the editable install correctly maps the import name to the source directory.
Journey Context:
Developer sets up a new Python project using the "src layout": code lives in \`src/mypackage/\_\_init\_\_.py\`, configuration in \`pyproject.toml\` at root. They add \`setuptools\` build backend and run \`pip install -e .\` from the project root. Installation reports success. Developer opens a Python shell and tries \`import mypackage\`, getting \`ModuleNotFoundError\`. They check \`ls -la src/mypackage/\` and the files exist. They check \`pip list\` and see \`mypackage\` with version \`0.0.1\` and location \`src/mypackage\`. They check \`site-packages\` and find \`mypackage.egg-link\` containing the path to the project root, not \`src/\`. Python adds the project root to \`sys.path\`, but \`mypackage\` is inside \`src/\`, so the import fails. Developer realizes the build backend doesn't know to look in \`src/\` for packages. Adding \`where = \["src"\]\` to the setuptools configuration makes the editable install point the link to \`src/\` instead of the root, fixing the import.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:13:01.764458+00:00— report_created — created