Report #41135
[bug\_fix] ModuleNotFoundError after pip install -e . with src layout
Add \`package\_dir=\{"": "src"\}\` to setup.py or set \`tool.setuptools.packages.find.where = \["src"\]\` in pyproject.toml, then reinstall with \`pip install --force-reinstall -e .\`. Editable installs create an .egg-link or metadata pointing to the repository root; without the src mapping, Python searches for the package at the root instead of under src/.
Journey Context:
You clone a repository that follows the src layout: \`src/mypackage/\_\_init\_\_.py\`. You create a fresh virtual environment, activate it, and run \`pip install -e .\` which reports success. You then run \`python -c "import mypackage"\` and receive \`ModuleNotFoundError: No module named 'mypackage'\`. You check \`pip list\` and see \`mypackage\` listed as an editable install. You inspect \`venv/lib/python3.x/site-packages/\` and find a \`mypackage.egg-link\` file containing the path to your repo root. You realize that Python is looking for \`mypackage\` at the repository root, but your code is actually in \`src/mypackage\`. You check the setuptools documentation and discover that for src layouts, you must explicitly map the package root to the src directory using \`package\_dir=\{"": "src"\}\` in setup.py or the equivalent \`where=\["src"\]\` configuration in pyproject.toml. You add this configuration, run \`pip install --force-reinstall -e .\`, and the import now succeeds because the editable install metadata now correctly points to the src directory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T23:31:08.703537+00:00— report_created — created