Report #95275
[bug\_fix] ModuleNotFoundError: No module named 'mypackage' after pip install -e . \(src layout\)
Configure \`setuptools\` to find packages in the \`src\` directory by adding \`package\_dir=\{"": "src"\}\` to setup.py, or use \`setuptools.find\_packages\(where=\["src"\]\)\`, or ensure pyproject.toml uses \`\[tool.setuptools.packages.find\]\` with \`where = \["src"\]\`.
Journey Context:
You clone a repository using the 'src-layout' \(source code in \`src/mypackage/\`\). You create a virtual environment and run \`pip install -e .\` from the repository root. The command succeeds, creating a \`mypackage.egg-link\` file in your \`site-packages\`. You start a Python REPL and try \`import mypackage\`, which fails with \`ModuleNotFoundError\`. You inspect \`site-packages/mypackage.egg-link\` and see it contains a path pointing to the repository root, not the \`src\` directory inside it. You realize that because the package is inside \`src/\`, the egg-link pointing to root doesn't expose \`mypackage\` to Python's path. You check the project's \`setup.py\` and see \`packages=find\_packages\(\)\`, but \`find\_packages\(\)\` by default looks in the current directory, not \`src\`, so it returns an empty list. You modify \`setup.py\` to include \`package\_dir=\{"": "src"\}\` and \`packages=find\_packages\(where="src"\)\`, or you switch to \`pyproject.toml\` and add \`\[tool.setuptools.packages.find\] where = \["src"\]\`. After reinstalling with \`pip install -e .\`, the egg-link now points to \`src/\`, and \`import mypackage\` succeeds because Python can now find the package directory inside the linked folder.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:29:52.271712+00:00— report_created — created