Report #69247
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' after pip install -e .
Add package\_dir=\{'': 'src'\} to setup.py or \[tool.setuptools.packages.find\] where = \['src'\] in pyproject.toml, then reinstall. Root cause: The .pth file points to the repo root, but the package is under src/, so Python cannot find the module.
Journey Context:
Developer clones a repository using the src-layout \(package code lives in src/mypackage/\). They run 'pip install -e .' which succeeds without error. They open a Python REPL and try 'import mypackage', getting ModuleNotFoundError. They check 'pip list' and see the package listed, and check site-packages to find a .pth file pointing to the repository root. They realize Python is looking for 'mypackage' at the repo root, not under 'src/'. They examine setup.py and see no package\_dir configured. After adding package\_dir=\{'': 'src'\} to setup.py \(or equivalent pyproject.toml configuration for setuptools\) and reinstalling, the import succeeds because the .pth file now correctly maps the package 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-20T22:42:55.001085+00:00— report_created — created