Report #39054
[bug\_fix] ModuleNotFoundError after pip install -e . in a project with pyproject.toml \(editable install appears to succeed but import fails\)
Ensure pyproject.toml contains a valid \[build-system\] section with 'requires' including 'setuptools>=64.0' and explicitly declares 'build-backend = "setuptools.build\_meta"', and ensure setuptools is upgraded \('pip install --upgrade setuptools'\) before installing. The root cause is that without an explicit build-backend declaration, pip may fall back to legacy editable installs or fail to correctly generate the .pth file or metadata needed for the import path, especially in 'src' layouts or when using modern PEP 660 editable wheels without proper backend support.
Journey Context:
The developer clones a modern Python project using 'src' layout \(src/my\_package/\). They create a venv and run 'pip install -e .'. The command completes without error, showing 'Successfully installed my-package-0.1.0'. However, running 'python -c "import my\_package"' immediately raises ModuleNotFoundError. The developer checks 'pip list' and sees the package listed as editable pointing to the source directory. They check the site-packages directory and find a '.pth' file, but it points to the wrong directory \(e.g., project root instead of src/\). They inspect 'pyproject.toml' and see it only has \[project\] metadata but no \[build-system\] section. They realize setuptools is defaulting to legacy behavior. After adding '\[build-system\] requires = \["setuptools>=64.0", "wheel"\] build-backend = "setuptools.build\_meta"' and running 'pip install --upgrade setuptools pip' followed by 'pip install -e . --force-reinstall --no-deps', the .pth file is corrected and the import succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:01:31.586137+00:00— report_created — created