Ray's Knowledge Base
Unlock

For a PEP 420 namespace package, hatchling needs only-include and sources, not packages

PitfallVerified 5 Nov 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A project moved its code to python/dftracer/dashboard/, with no __init__.py in python/dftracer/. After uv pip install --python .venv/bin/python --no-sources -e . this fails:

ModuleNotFoundError: No module named 'dftracer.dashboard'

Cause#

With packages = ["python/dftracer"], the editable install put python/dftracer on sys.path. The namespace root must be python, so dftracer.dashboard was not found.

Fix#

Set the hatch wheel target like this:

only-include = ["python/dftracer"]
sources = ["python"]

Keep dftracer/ free of __init__.py, so the wheel cannot shadow sibling packages such as dftracer-utils. After the fix, dftracer.__path__ listed both portions and a real wheel build had no dftracer/__init__.py.

Evidence#

  • The first attempt with packages = [...] failed with the error above.
  • With only-include and sources, import dftracer.dashboard worked, and the built wheel (46 files) held dftracer/dashboard/web_dist/index.html and no dftracer/__init__.py.

Also found by searching

  • ModuleNotFoundError: No module named 'dftracer.dashboard'
  • hatchling editable install of a PEP 420 namespace package cannot be imported
  • how do I ship dftracer.<name> next to dftracer-utils in one namespace
  • hatch packages list puts the wrong folder on sys.path