{"record":{"id":"368b4f383e2d9007","repo":"HKUDS/Vibe-Trading","slug":"rapidocr-not-installed-pip-install-rapidocr-onnxr","errorCode":null,"errorMessage":"RapidOCR not installed: pip install rapidocr_onnxruntime","messagePattern":"RapidOCR not installed: pip install rapidocr_onnxruntime","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/src/tools/ocr/rapid_ocr.py","lineNumber":32,"sourceCode":"\n    def __init__(self) -> None:\n        # Lazy init: RapidOCR() loaded inside is_available() / recognize().\n        # _select_first_local() probes every registered engine, so __init__\n        # must stay cheap (attribute assignment only).\n        self._engine = None\n\n    def is_available(self) -> bool:\n        try:\n            from rapidocr_onnxruntime import RapidOCR  # type: ignore\n            if self._engine is None:\n                self._engine = RapidOCR()\n            return True\n        except ImportError:\n            return False\n\n    def recognize(self, image: np.ndarray) -> str:\n        if not self.is_available():\n            raise RuntimeError(\"RapidOCR not installed: pip install rapidocr_onnxruntime\")\n        result, _ = self._engine(image)\n        if not result:\n            return \"\"\n        return \"\\n\".join(item[1] for item in result)\n\n\n# Self-register to built-in engine table\nfrom src.tools.ocr.engine import register_builtin  # noqa: E402\n\nregister_builtin(\"rapid\", RapidOcrEngine)\n","sourceCodeStart":14,"sourceCodeEnd":43,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/tools/ocr/rapid_ocr.py#L14-L43","documentation":"Raised by RapidOCREngine.recognize when the rapidocr_onnxruntime package cannot be imported. The engine lazily checks availability via is_available() and refuses to run OCR on a machine where the dependency was never installed or is installed in a different environment. It is a missing-dependency RuntimeError, not a model or image problem.","triggerScenarios":"Calling agent/src/tools/ocr/rapid_ocr.py recognize(image) on any process where `import rapidocr_onnxruntime` fails: package not installed, installed in another venv/conda env, or the runtime Python used by the agent differs from the one where deps were pip-installed.","commonSituations":"Fresh clones without optional extras; Docker images that omitted the OCR extra; CI environments; deploying the agent with a system Python while rapidocr was installed in a project venv; onnxruntime wheel incompatibility causing the import to fail indirectly.","solutions":["pip install rapidocr_onnxruntime into the exact interpreter the agent runs under (python -m pip install rapidocr_onnxruntime)","Verify with: python -c \"import rapidocr_onnxruntime\" in the agent's environment","If OCR is optional, call is_available() before recognize() and degrade gracefully","In Docker, add the package to the image and rebuild"],"exampleFix":"// before\nengine = RapidOCREngine()\ntext = engine.recognize(img)\n// after\nengine = RapidOCREngine()\nif not engine.is_available():\n    text = \"\"  # or log warning / skip OCR\nelse:\n    text = engine.recognize(img)","handlingStrategy":"type-guard","validationCode":"from agent.src.tools.ocr.rapid_ocr import RapidOCREngine\nengine = RapidOCREngine()\nif not engine.is_available():\n    raise SystemExit(\"Install rapidocr_onnxruntime or disable OCR features\")","typeGuard":"def ocr_ready(engine: RapidOCREngine) -> bool:\n    return engine.is_available()","tryCatchPattern":"try:\n    text = engine.recognize(img)\nexcept RuntimeError as e:\n    if \"not installed\" in str(e):\n        text = \"\"  # graceful degradation\n    else:\n        raise","preventionTips":["Pin rapidocr_onnxruntime in requirements with the OCR extra","Verify imports in the deployment environment before enabling OCR tools","Gate OCR features behind an is_available() capability check"],"tags":["ocr","dependency","import-error","python"],"backgroundTag":"missing-optional-dependency","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}