{"record":{"id":"d4a684e5c62433f0","repo":"PaddlePaddle/PaddleOCR","slug":"pyyaml-is-required-to-read-inference-yml","errorCode":null,"errorMessage":"PyYAML is required to read inference.yml","messagePattern":"PyYAML is required to read inference\\.yml","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"deploy/ios_demo/scripts/ocr_reference_run.py","lineNumber":51,"sourceCode":"import json\nimport sys\nfrom pathlib import Path\nfrom typing import Any, Dict, List, Sequence\n\n\ndef _paddleocr_package_root() -> Path:\n    return Path(__file__).resolve().parents[3]\n\n\ndef _default_ios_models_root() -> Path:\n    return Path(__file__).resolve().parent.parent / \"PaddleOCRDemo\" / \"Models\"\n\n\ndef _load_yaml_model_name(path: Path) -> str:\n    try:\n        import yaml\n    except ImportError as exc:\n        raise RuntimeError(\"PyYAML is required to read inference.yml\") from exc\n    with path.open(\"r\", encoding=\"utf-8\") as f:\n        data = yaml.safe_load(f)\n    return data[\"Global\"][\"model_name\"]\n\n\ndef _numpy_to_python(obj: Any) -> Any:\n    if obj is None:\n        return None\n    if hasattr(obj, \"tolist\"):\n        return obj.tolist()\n    if isinstance(obj, (list, tuple)):\n        return [_numpy_to_python(x) for x in obj]\n    if isinstance(obj, dict):\n        return {k: _numpy_to_python(v) for k, v in obj.items()}\n    elif isinstance(obj, (str, int, float, bool)):\n        return obj\n    return str(obj)\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/deploy/ios_demo/scripts/ocr_reference_run.py#L33-L69","documentation":"RuntimeError raised by ocr_reference_run.py when `import yaml` fails while loading a PaddleOCR model's inference.yml. The script needs PyYAML to read Global.model_name from the model config; the error names the missing dependency explicitly.","triggerScenarios":"Running the iOS reference OCR script in a Python environment where PyYAML is not installed; a venv created from a partial requirements list; using a stripped-down runtime (e.g. slim docker image) without yaml.","commonSituations":"Fresh clone plus `pip install -r requirements.txt` where pyyaml is absent; system python vs venv mismatch so a globally installed yaml is not visible.","solutions":["Install PyYAML into the active environment: `pip install pyyaml`.","Verify with `python -c \"import yaml; print(yaml.__version__)\"` in the same interpreter the script uses.","Add pyyaml to the deploy/ios_demo requirements file if it is missing so the env is reproducible."],"exampleFix":"// before\n$ python deploy/ios_demo/scripts/ocr_reference_run.py ...\nRuntimeError: PyYAML is required to read inference.yml\n\n// after\n$ pip install pyyaml\n$ python deploy/ios_demo/scripts/ocr_reference_run.py ...","handlingStrategy":"validation","validationCode":"def pyyaml_available() -> bool:\n    try:\n        import yaml  # noqa: F401\n        return True\n    except ImportError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    model_name = _load_yaml_model_name(yml_path)\nexcept RuntimeError as e:\n    if \"PyYAML\" in str(e):\n        subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", \"pyyaml\"])\n        model_name = _load_yaml_model_name(yml_path)\n    else:\n        raise","preventionTips":["Declare pyyaml in the environment requirements for deploy/ios_demo scripts.","After creating a venv, smoke-test imports the scripts need (yaml, onnx, numpy) before long runs."],"tags":["python","dependency","pyyaml","ios-demo"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}