datawhalechina/hello-agents · error · FileNotFoundError

数据文件不存在: {self.data_path}

Error message

数据文件不存在: {self.data_path}

What it means

FileNotFoundError raised by the HumanVerificationUI constructor when the JSON data file passed as data_path does not exist on disk. The class immediately loads problems at construction time, so instantiation fails fast on a bad path.

Source

Thrown at code/chapter12/data_generation/human_verification_ui.py:32

class HumanVerificationUI:
    """人工验证界面"""
    
    def __init__(self, data_path: str):
        """
        初始化验证界面
        
        Args:
            data_path: 生成数据的JSON文件路径
        """
        self.data_path = data_path
        self.problems = self._load_problems()
        self.current_index = 0
        self.verifications = self._load_verifications()
        
    def _load_problems(self) -> List[Dict[str, Any]]:
        """加载题目数据"""
        if not os.path.exists(self.data_path):
            raise FileNotFoundError(f"数据文件不存在: {self.data_path}")
        
        with open(self.data_path, 'r', encoding='utf-8') as f:
            return json.load(f)
    
    def _load_verifications(self) -> Dict[str, Any]:
        """加载已有的验证结果"""
        verification_path = self.data_path.replace(".json", "_verifications.json")
        
        if os.path.exists(verification_path):
            with open(verification_path, 'r', encoding='utf-8') as f:
                return json.load(f)
        
        return {}
    
    def _save_verifications(self):
        """保存验证结果"""
        verification_path = self.data_path.replace(".json", "_verifications.json")
        

View on GitHub (pinned to 606a07d341)

Solutions

  1. Run the data generation script first so the JSON file exists at the expected path
  2. Use an absolute path (e.g. built from os.path.dirname(__file__)) instead of a bare relative filename
  3. Verify the path with os.path.exists before constructing the UI

Example fix

# before
ui = HumanVerificationUI('aime_problems.json')  # relative -> may miss

# after
import os
path = os.path.join(os.path.dirname(__file__), 'aime_problems.json')
if not os.path.exists(path):
    raise SystemExit(f'Run the generator first; missing {path}')
ui = HumanVerificationUI(path)
Defensive patterns

Strategy: validation

Validate before calling

import os

def ensure_data_file(path: str) -> str:
    path = os.path.abspath(path)
    if not os.path.exists(path):
        raise SystemExit(f'{path} not found — run the generator script first')
    return path

Try / catch

try:
    ui = HumanVerificationUI(path)
except FileNotFoundError as e:
    raise SystemExit(f'{e} — generate the dataset or fix the path')

Prevention

When it happens

Trigger: Passing a path to a dataset that was never generated (e.g. running the verification UI before aime_generator.py wrote its output); wrong filename or relative path evaluated from a different working directory; data written to another folder.

Common situations: Skipping the generation step in the chapter's workflow; running the UI from the repo root while the JSON lives in code/chapter12/data_generation/output/; moving generated files after a cleanup.


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/e148e993b07a0add. Report an issue: GitHub.