Report #88878
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' after pip install -e . in a src-layout project
Add \[tool.setuptools.package-dir\] "" = "src" and \[tool.setuptools.packages.find\] where = \["src"\] to pyproject.toml \(or package\_dir=\{"":"src"\} in setup.py\) so setuptools maps the package root to the src/ directory during the editable install.
Journey Context:
Developer clones a modern Python repository using the src-layout \(package code lives in src/mypackage/\). They create a fresh venv and run 'pip install -e .'. The installation appears successful. However, running 'python -c "import mypackage"' immediately raises ModuleNotFoundError. Inspecting .venv/lib/python3.x/site-packages/ reveals a mypackage.pth file containing only the path to the repository root, not the src/ subdirectory. Python therefore searches for 'mypackage' in the repo root where only pyproject.toml exists, not the actual package. The developer tries adding 'package\_dir=\{"":"src"\}' but in the wrong section. After checking setuptools docs, they realize that without explicit configuration, setuptools assumes a flat-layout and the editable install links the wrong directory. The fix explicitly tells setuptools that packages are located under src/, causing the .pth file to point to src/ or the mapping to be correct, allowing Python to find the module.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:46:18.075967+00:00— report_created — created