Report #49740
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' after 'pip install -e .' in a src-layout project
Add explicit package discovery configuration to pyproject.toml: under \[tool.setuptools.packages.find\] set 'where = \["src"\]', and set 'package\_dir = \{"": "src"\}'. Then reinstall.
Journey Context:
Developer clones a repository using the 'src' layout \(code lives in src/mypackage/\). They create a fresh venv, activate it, and run 'pip install -e .'. The command succeeds and the package appears in 'pip list'. However, opening a REPL and running 'import mypackage' immediately raises 'ModuleNotFoundError'. The developer checks 'venv/lib/pythonX.Y/site-packages/' and sees a '.egg-link' file pointing to the repo root, but the path does not include 'src/'. Realizing that modern setuptools \(PEP 621\) does not automatically discover packages in subdirectories unless configured, they add the \[tool.setuptools.packages.find\] table with 'where = \["src"\]' and 'package\_dir = \{"": "src"\}'. After a fresh 'pip install -e .', the import succeeds because the metadata now correctly maps the import name to the 'src/' directory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:58:22.423609+00:00— report_created — created