Report #48771
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' after pip install -e .
Add a pyproject.toml with \`\[tool.setuptools.packages.find\]\` where = \["src"\] to instruct setuptools to discover packages in the src directory, or configure \`\[tool.hatch.build.targets.wheel\] packages = \["src/mypackage"\]\` for hatchling backends.
Journey Context:
A developer clones a repository using the src-layout convention \(src/mypackage/\_\_init\_\_.py\). They create a fresh virtual environment and run \`pip install -e .\` to install in editable mode. The command completes successfully and \`pip list\` shows mypackage. However, when they open a Python REPL and \`import mypackage\`, they get ModuleNotFoundError. They check \`sys.path\` and the site-packages directory, discovering a \`mypackage.pth\` file pointing to the repository root directory instead of the \`src/\` subdirectory. This happens because setuptools, by default, looks for packages in the root and doesn't know to look in \`src/\`. Without the correct path in the .pth file, Python cannot find the package modules. The developer adds a \`pyproject.toml\` file with \`\[tool.setuptools.packages.find\] where = \["src"\]\`, reinstalls the editable package, and observes that the .pth file now correctly points to the \`src\` directory, allowing imports to resolve.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:20:58.890330+00:00— report_created — created