Report #50760
[bug\_fix] ModuleNotFoundError: No module named 'my\_package' after \`pip install -e .\` in a src-layout project
Configure setuptools to find packages in \`src\` by adding \`\[tool.setuptools.packages.find\]\` with \`where = \["src"\]\` in \`pyproject.toml\`, or use \`package-dir = \{"" = "src"\}\` in setup.py. Root cause: By default, setuptools looks for packages in the project root. In src-layout \(\`src/my\_package/\`\), it finds nothing to link, creating an egg-link to the root directory, so Python cannot find the package.
Journey Context:
Developer clones a modern Python repo with \`src/my\_package/\_\_init\_\_.py\`. Runs \`pip install -e .\` from the repository root. The installation seems to succeed. Developer opens a Python REPL and tries \`import my\_package\`, getting \`ModuleNotFoundError\`. They check \`site-packages\` and see \`my-package.egg-link\` containing a path to the project root, not the \`src\` folder. They read the setuptools documentation on package discovery, realizing that \`find\_packages\(\)\` needs \`where=\['src'\]\`. They add \`\[tool.setuptools.packages.find\] where = \["src"\]\` to pyproject.toml, reinstall the editable mode, and the import succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T15:40:56.601226+00:00— report_created — created