Report #56366
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' immediately after 'pip install -e .' in a repository with a src/ directory layout
Add 'package\_dir=\{"": "src"\}' in setup.py or '\[tool.setuptools.packages.find\]\\nwhere = \["src"\]' in pyproject.toml, then reinstall. Root cause: setuptools defaults to looking for packages in the project root; without the mapping, the editable install points to an empty root directory instead of src/.
Journey Context:
You clone a repository using the src layout \(code lives in src/mypackage/\). You create a venv, activate it, and run 'pip install -e .' from the repo root. The install succeeds. You open Python and try 'import mypackage', receiving ModuleNotFoundError. You check 'pip list' and see mypackage listed, so you suspect PYTHONPATH. You print\(sys.path\) and see the repo root, but not src/. You realize setuptools didn't map the src directory because package\_dir was unset. Adding the mapping makes the editable link point 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-20T01:06:17.967264+00:00— report_created — created