Report #81648
[bug\_fix] ModuleNotFoundError after \`pip install -e .\` in src-layout project
Configure \`tool.setuptools.packages.find\` with \`where = \["src"\]\` in pyproject.toml \(or \`package\_dir\` and \`find\_packages\(where='src'\)\` in setup.py\) so that PEP 660 editable wheels correctly map the import name to the src directory.
Journey Context:
Developer migrates a project to modern packaging standards using a \`src/\` directory structure \(src/mypackage/\). They create a pyproject.toml with \`\[build-system\]\` using setuptools. They run \`pip install -e .\` which completes successfully and the package appears in \`pip list\`. However, when they try \`import mypackage\`, they get ModuleNotFoundError. They check \`python -c "import sys; print\(sys.path\)"\` and don't see the src directory listed. They inspect the \`.venv/lib/python3.x/site-packages/\` and see an \`.egg-link\` file or a \`\_\_editable\_\_.mypackage.pth\` file \(depending on setuptools version\) pointing to the project root, not the src directory. The root cause is that modern PEP 660 editable wheels require explicit configuration of where the packages live when not at the repository root. Without \`tool.setuptools.packages.find.where = \["src"\]\`, setuptools assumes the package is at the root, creates an editable install pointing there, finds nothing, and the import fails. Adding the configuration tells setuptools to look in \`src/\` for the packages when building the editable wheel metadata, ensuring the path mapping correctly points to the actual package location.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:38:19.689213+00:00— report_created — created