HKUDS/Vibe-Trading · error · RegistryError
{alpha.id}: could not build import spec for {py_file}
Error message
{alpha.id}: could not build import spec for {py_file} What it means
When the registry uses a filesystem loader, it builds an importlib spec from the recorded .py path. If spec_from_file_location returns None or a spec without a loader (unrecognized extension, path issues), this RegistryError is raised.
Source
Thrown at agent/src/factors/registry.py:366
raise RegistryError(f"{alpha_id}: module has no compute() function")
try:
result = compute_fn(panel)
except Exception as exc: # noqa: BLE001 — isolate compute failure
raise RegistryError(f"{alpha_id}: compute() raised: {exc}") from exc
return self._validate_output(alpha_id, result, panel)
def _load_module(self, alpha: Alpha) -> ModuleType:
if not self._use_filesystem_loader:
return importlib.import_module(alpha.module_path)
py_file = self._py_paths[alpha.id]
cached = sys.modules.get(alpha.module_path)
if cached is not None and getattr(cached, "__file__", None) == str(py_file):
return cached
spec = importlib.util.spec_from_file_location(alpha.module_path, py_file)
if spec is None or spec.loader is None:
raise RegistryError(f"{alpha.id}: could not build import spec for {py_file}")
module = importlib.util.module_from_spec(spec)
sys.modules[alpha.module_path] = module
try:
spec.loader.exec_module(module)
except Exception:
sys.modules.pop(alpha.module_path, None)
raise
return module
@staticmethod
def _validate_output(
alpha_id: str,
result: Any,
panel: dict[str, pd.DataFrame],
) -> pd.DataFrame:
if not isinstance(result, pd.DataFrame):
raise RegistryError(
f"{alpha_id}: compute() returned {type(result).__name__}, expected DataFrame"View on GitHub (pinned to 80ffdda44c)
Solutions
- Ensure the zoo contains real .py files with standard names
- Re-scan the registry so _py_paths reflects current files
- Check the path printed in the message exists and ends with .py
Defensive patterns
Strategy: try-catch
Validate before calling
import importlib.util spec = importlib.util.spec_from_file_location(mp, py_file) if spec is None or spec.loader is None: skip(aid)
Try / catch
try:
out = registry.compute(aid, panel)
except RegistryError as e:
if 'import spec' in str(e): skip(aid)
else: raise Prevention
- Keep only .py modules in the zoo directory
- Re-scan registry after moving files
When it happens
Trigger: _load_module for an alpha whose recorded path is not a loadable .py file — wrong extension, empty path string, or an exotic filesystem importlib can't build a loader for.
Common situations: Zoo directory containing .pyc/.so or renamed files picked up by the scanner; registry state persisted and paths changed; platform differences in importlib loaders.
Related errors
- {alpha_id}: import failed: {exc}
- unknown zoo {v!r}; expected one of {sorted(_VALID_ZOOS)}
- unknown panel column: {column}
- invalid {kind} {token!r}: must match {_ID_RE.pattern}
- {path.name}: {size}B exceeds {_MAX_PY_BYTES}B cap
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/d5a93d5a626087e4.
Report an issue: GitHub.