Report #82349
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' after pip install -e . in src-layout project
Add explicit package discovery configuration to pyproject.toml: \[tool.setuptools.packages.find\] where = \["src"\]. Alternatively, use pip install -e . --config-settings editable\_mode=compat. The root cause is that modern setuptools defaults to PEP 660 'strict' editable mode, which requires explicit mapping of the source tree; without 'where' pointing to src/, the .pth file points to the project root instead of the src/ directory containing the code.
Journey Context:
You clone a repository using the src-layout convention \(src/mypackage/\_\_init\_\_.py\). You create a fresh venv, activate it, and run pip install -e . which completes successfully. You open a Python REPL and try import mypackage, but get ModuleNotFoundError. You check pip list and see mypackage 0.0.0 is installed. You inspect .venv/lib/python3.x/site-packages/ and find mypackage.pth containing a path to the project root, not the src/ subdirectory. You try editing the .pth file manually and it works temporarily. You research and discover PEP 660 and setuptools' strict editable mode. You add \[tool.setuptools.packages.find\] where = \["src"\] to pyproject.toml, reinstall with pip install -e ., and observe that the .pth file now correctly points to the src/ directory, resolving the import.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:49:09.246709+00:00— report_created — created