Report #54979
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' immediately after \`pip install -e .\` in a src-layout project
Configure setuptools to find packages in the \`src\` directory by adding to \`pyproject.toml\`: \`\`\`toml \[tool.setuptools.packages.find\] where = \["src"\] \`\`\` Alternatively, in \`setup.py\`, use \`package\_dir=\{'': 'src'\}\`. The root cause is that an editable install \(PEP 660\) creates a \`.pth\` file in site-packages. If the package code is under \`src/mypackage/\` but the build backend is not told to look in \`src\`, the .pth points to the repo root where \`mypackage\` doesn't exist as a top-level folder.
Journey Context:
Developer clones a repo with structure \`repo/src/mypackage/\_\_init\_\_.py\`. They create a venv and run \`pip install -e .\` from \`repo/\`. The installation succeeds. They open Python and \`import mypackage\` raises ModuleNotFoundError. They check \`pip list\` and see \`mypackage 0.1.0\` installed. They inspect \`venv/lib/python3.x/site-packages/\` and find a file named \`\_\_editable\_\_.mypackage-0.1.0.pth\`. They open it and see it contains \`/path/to/repo\`. They realize Python is looking for \`mypackage\` in \`/path/to/repo/mypackage\`, but the actual code is at \`/path/to/repo/src/mypackage\`. They check \`pyproject.toml\` and see it only has \`\[build-system\]\` but no \`\[tool.setuptools.packages.find\]\` section. They add the configuration to tell setuptools to look in \`src\`. They reinstall with \`pip install -e .\`. The .pth file now contains \`/path/to/repo/src\`. Python can now find \`mypackage\` under \`src/\`. Import succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:46:28.838394+00:00— report_created — created