Report #22621
[bug\_fix] ModuleNotFoundError after pip install -e . in src layout
Configure the build backend \(setuptools\) to recognize the source directory by setting \`package\_dir=\{"": "src"\}\` in setup.py or \`\[tool.setuptools.packages.find\] where = \["src"\]\` in pyproject.toml, then reinstall.
Journey Context:
You clone a repository with a \`src/\` directory containing the package \(e.g., \`src/mylib/\_\_init\_\_.py\`\). You create a venv, activate it, and run \`pip install -e .\` from the repo root. The installation succeeds. You open a Python REPL and \`import mylib\`, getting ModuleNotFoundError. You check \`pip list\` and see \`mylib\` listed with version 0.0.0. You check \`site-packages\` and find a \`mylib.egg-link\` file pointing to the repo root, not the \`src\` directory. The issue is that setuptools, by default, looks for packages in the root directory. Since the code is in \`src/\`, setuptools creates an empty package metadata or points to the wrong place. The fix involves editing \`pyproject.toml\` to add \`\[tool.setuptools.packages.find\] where = \["src"\]\` \(or in setup.py \`package\_dir=\{'': 'src'\}\`\) so that \`pip install -e .\` correctly maps the package name to the \`src/\` subdirectory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:22:56.970440+00:00— report_created — created