Report #76554
[bug\_fix] ModuleNotFoundError after pip install -e . in src-layout project
In \`pyproject.toml\`, configure setuptools with \`\[tool.setuptools.packages.find\]\` specifying \`where = \["src"\]\`, or in \`setup.py\` use \`packages=find\_packages\(where="src"\)\` and \`package\_dir=\{"": "src"\}\`. Ensure \`pip>=21.3\` and \`setuptools>=64\` for PEP 660 editable support.
Journey Context:
You modernize your project to use the src-layout \(package code in \`src/mypackage/\` instead of \`mypackage/\` at root\). You update \`setup.py\` to point to \`src/\`, run \`pip install -e .\`, which succeeds. You open a Python REPL in the project root and \`import mypackage\` raises ModuleNotFoundError. You check \`site-packages\` and see a \`.pth\` file or import hook for your package, but \`python -c "import sys; print\('\\n'.join\(sys.path\)\)"\` doesn't include your \`src/\` directory. You realize that modern PEP 660 editable installs use import hooks rather than path manipulation, and if setuptools isn't explicitly told about the \`src\` directory via \`package\_dir\` or \`find\_packages\(where="src"\)\`, it creates an editable install that points to the wrong location or fails to map the import 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-21T11:05:03.064245+00:00— report_created — created