79523123

Date: 2025-03-20 13:42:43
Score: 0.5
Natty:
Report link

After some digging, I finally got it to work.

import importlib
import sys

# 1. manually create a namespace package specification
spec = importlib.machinery.ModuleSpec("xxx", None)
spec.submodule_search_locations = ["/path/xxx"]

# 2. import module from the spec
xxx = importlib.util.module_from_spec(spec)

# 3. add it to global cache
sys.modules["xxx"] = xxx
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: John Ao