rohitg00/ai-engineering-from-scratch · error · ImportError

sibling module not found

Error message

sibling module not found: {sibling}

What it means

_load_sibling imports a neighboring lesson's main.py by path (../../<lesson_dir>/code/main.py) so the end-to-end runner can reuse its metrics; this ImportError fires when that computed path does not exist, i.e. the lesson directory was renamed, moved, or not checked out.

Solutions

  1. Verify the lesson directory name matches exactly (e.g. '71-classical-metrics')
  2. Restore the missing sibling lesson directory in your checkout
  3. Point the runner at an explicit absolute path if the repo layout differs
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phases/19-capstone-projects/75-end-to-end-eval-runner/code/main.py:27 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/2b64a7d3c6d2ba82. Report an issue: GitHub.

Appendix: source

Thrown at phases/19-capstone-projects/75-end-to-end-eval-runner/code/main.py:27

from __future__ import annotations

import importlib.util
import json
import os
import random
import sys
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
from dataclasses import dataclass, field
from typing import Callable, Sequence


def _load_sibling(lesson_dir: str, module_name: str = "main"):
    here = os.path.dirname(os.path.abspath(__file__))
    sibling = os.path.normpath(os.path.join(here, "..", "..", lesson_dir, "code", "main.py"))
    if not os.path.isfile(sibling):
        raise ImportError(f"sibling module not found: {sibling}")
    mod_name = f"_sibling_{lesson_dir.replace('-', '_')}"
    spec = importlib.util.spec_from_file_location(mod_name, sibling)
    if spec is None or spec.loader is None:
        raise ImportError(f"could not build spec for {sibling}")
    module = importlib.util.module_from_spec(spec)
    sys.modules[mod_name] = module
    spec.loader.exec_module(module)
    return module


spec_mod = _load_sibling("70-task-spec-format")
metrics_mod = _load_sibling("71-classical-metrics")
exec_mod = _load_sibling("72-code-exec-metric")
calib_mod = _load_sibling("73-perplexity-calibration")
board_mod = _load_sibling("74-leaderboard-aggregation")


TaskSpec = spec_mod.TaskSpec

View on GitHub (pinned to 39ea8a1c6d)