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

h5py is required for this lesson. Install with: pip install…

Error message

h5py is required for this lesson. Install with: pip install h5py

What it means

Import guard at module load: the optional h5py dependency is missing, so HDF5 shard writing/reading for this lesson cannot proceed and the program exits via SystemExit with install instructions.

Solutions

  1. pip install h5py in the active environment
  2. Confirm the correct virtualenv/interpreter is used for this lesson
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at phases/19-capstone-projects/43-hdf5-tokenized-corpus/code/main.py:34 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/10a018d44907fa7f. Report an issue: GitHub.

Appendix: source

Thrown at phases/19-capstone-projects/43-hdf5-tokenized-corpus/code/main.py:34

from __future__ import annotations

import hashlib
import json
import random
import struct
import sys
import tempfile
from dataclasses import asdict, dataclass, field
from pathlib import Path
from typing import Iterable, Iterator

import numpy as np

try:
    import h5py
except ImportError as exc:
    raise SystemExit(
        "h5py is required for this lesson. Install with: pip install h5py"
    ) from exc


DEFAULT_CHUNK_SIZE = 8192
DEFAULT_WINDOW_SIZE = 64
BOUNDARY_TOKEN_ID = 0
TOKEN_DTYPE = np.uint16


@dataclass
class ShardWriteResult:
    """Per-shard write outcome."""

    shard_id: str
    path: str
    token_count: int
    document_count: int

View on GitHub (pinned to 39ea8a1c6d)