Report #23115
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' after \`pip install -e .\` in a src-layout project
Configure setuptools to find packages in the \`src\` directory by setting \`\[tool.setuptools.packages.find\]\` with \`where = \["src"\]\` in pyproject.toml, or use \`package\_dir = \{"": "src"\}\` in setup.py. Alternatively, set \`PYTHONPATH=src\` temporarily. Root cause: In a src-layout \(\`src/mypackage/...\`\), the project root is not in sys.path by default. Without telling setuptools where to find the packages, pip installs an empty metadata directory or fails to map 'mypackage' to the src directory, so Python cannot find the module despite the editable install appearing to succeed.
Journey Context:
You have a project structured with \`src/mypackage/\_\_init\_\_.py\` \(src-layout\). You run \`pip install -e .\` from the project root. It completes without error. You open a Python REPL in the project root and \`import mypackage\`, getting \`ModuleNotFoundError: No module named 'mypackage'\`. You check \`pip list\` and see \`mypackage 0.1.0\` listed as an editable install. You check the \`.egg-link\` file in site-packages and see it points to the project root, not the src directory. You try \`cd src && python -c "import mypackage"\` and it works, confirming the path issue. You search 'editable install src layout' and find setuptools documentation mentioning \`package\_dir\` or \`find\_packages\(where='src'\)\`. You edit your pyproject.toml to add \`\[tool.setuptools.packages.find\] where = \["src"\]\`, reinstall with \`pip install -e .\`, and now \`import mypackage\` works from the project root. You realize the editable install must map the package name to the subdirectory, not just the repository root.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T17:12:15.954556+00:00— report_created — created