Report #12342
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' after pip install -e .
Configure \`setuptools\` in \`pyproject.toml\` with \`\[tool.setuptools.packages.find\] where = \["src"\]\` \(or in \`setup.py\` with \`package\_dir=\{'': 'src'\}, packages=find\_packages\(where='src'\)\`\). This tells the build backend to look for packages inside the \`src\` directory rather than the project root.
Journey Context:
A developer initializes a new project with a \`src\` directory structure: \`project\_root/src/mypackage/\_\_init\_\_.py\`. They create a \`pyproject.toml\` with \`\[build-system\]\` requires \`setuptools\` and \`\[project\]\` name "mypackage". They run \`pip install -e .\` from the root. The command succeeds, creating \`mypackage.egg-link\` in the venv. However, running \`python -c "import mypackage"\` raises \`ModuleNotFoundError\`. The developer inspects the egg-link file and sees it points to \`project\_root\` instead of \`project\_root/src\`. Realizing that setuptools by default searches for packages in the root, they modify \`pyproject.toml\` to add \`\[tool.setuptools.packages.find\] where = \["src"\]\`. After reinstalling with \`pip install -e .\`, the egg-link correctly points to the src directory, and imports succeed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:45:56.247353+00:00— report_created — created