Report #9692
[bug\_fix] Editable install fails for src-layout namespace packages \(PEP 420\)
Use 'pip install -e . --config-settings editable\_mode=compat' \(pip 22.3\+\) to use .pth path insertion instead of strict mapping, or configure setuptools to find packages in 'src' via \[tool.setuptools.packages.find\] where = \['src'\]. Root cause: PEP 660 editable installs default to 'strict' mode using a meta-path finder that maps import names to source paths. For PEP 420 implicit namespace packages \(no \_\_init\_\_.py\) in src-layout, strict mode cannot anchor the namespace root because there is no package directory to map, causing ModuleNotFoundError despite successful installation.
Journey Context:
You have a monorepo with 'src/mynamespace/subpackage/\_\_init\_\_.py' using PEP 420 implicit namespace \(no \_\_init\_\_.py in mynamespace\). You run 'pip install -e .' using setuptools with pyproject.toml. Installation reports success. You open Python and 'import mynamespace.subpackage' raises ModuleNotFoundError. You check site-packages and find 'mynamespace-subpackage.dist-info' but no mynamespace package. You examine the .pth file created and see it uses a strict editable redirect that points 'mynamespace.subpackage' directly to 'src/mynamespace/subpackage', but because mynamespace is a namespace without \_\_init\_\_.py, the import machinery cannot resolve the parent namespace. You consult setuptools docs and find that 'editable\_mode=compat' uses a .pth file that adds 'src/' to sys.path instead of strict mapping. You reinstall with 'pip install -e . --config-settings editable\_mode=compat'. Now src/ is in sys.path, Python sees mynamespace as a regular namespace package, and imports resolve correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:48:20.197410+00:00— report_created — created