Report #68050
[bug\_fix] ModuleNotFoundError or stale code after \`pip install -e .\` \(editable install\) in src-layout projects
Upgrade \`pip\`, \`setuptools\`, and \`wheel\` to latest, and configure \`\[tool.setuptools.packages.find\]\` with \`where = \["src"\]\` in \`pyproject.toml\` to correctly map the package root.
Journey Context:
Developer clones a modern Python project using a \`src/\` layout \(\`src/mypackage/\_\_init\_\_.py\`\). They create a fresh venv and run \`pip install -e .\`. The installation appears to succeed with no errors. However, \`import mypackage\` raises \`ModuleNotFoundError\`. Alternatively, the import succeeds but changes to the source code are not reflected on re-import \(stale code\). Investigation reveals that \`site-packages/mypackage.egg-link\` points to the repository root directory, not the \`src/\` subdirectory where the actual package code resides. This happens because the project uses modern PEP 660 editable installs via \`setuptools\`, but lacks the configuration to indicate the package is in \`src/\`. The fix is to add a \`pyproject.toml\` with \`\[tool.setuptools.packages.find\]\` specifying \`where = \["src"\]\`, or if using \`setup.py\`, to specify \`package\_dir=\{"": "src"\}\`. After reinstalling editable, the \`.pth\` file or redirect correctly points to \`src/\`, allowing imports to resolve.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:42:03.906976+00:00— report_created — created