Report #12173
[bug\_fix] ModuleNotFoundError after editable install of src-layout package
Configure setuptools to discover packages under \`src/\` by setting \`package\_dir=\{"": "src"\}\` in setup.py or \`\[tool.setuptools.packages.find\] where = \["src"\]\` in pyproject.toml, then reinstall with \`pip install -e .\`. This maps the import name to the source directory inside \`src/\`, ensuring Python finds the package metadata and modules.
Journey Context:
Developer clones a repository with a \`src/mypackage/\` directory, creates a fresh venv, and runs \`pip install -e .\`. The command succeeds, but attempting \`import mypackage\` raises \`ModuleNotFoundError\`. Checking \`site-packages\` shows a \`mypackage.egg-link\` file pointing to the repository root, not \`src/\`. The developer realizes Python is looking for \`mypackage\` directly in the repo root, but the code lives under \`src/\`. After reading the setuptools documentation on src-layout, they add the \`where=\["src"\]\` configuration to \`pyproject.toml\`, reinstall, and the import succeeds because the metadata now correctly maps the import to the subdirectory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:16:03.176717+00:00— report_created — created