{"record":{"id":"561817bc9adc4697","repo":"headroomlabs-ai/headroom","slug":"ollama-package-required-install-with-pip-install","errorCode":null,"errorMessage":"ollama package required. Install with: pip install ollama","messagePattern":"ollama package required\\. Install with: pip install ollama","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"headroom/evals/runners/before_after.py","lineNumber":123,"sourceCode":"                raise ImportError(\n                    \"anthropic package required. Install with: pip install anthropic\"\n                ) from e\n        elif self.llm_config.provider == \"openai\":\n            try:\n                import openai\n\n                return openai.OpenAI()\n            except ImportError as e:\n                raise ImportError(\n                    \"openai package required. Install with: pip install openai\"\n                ) from e\n        elif self.llm_config.provider == \"ollama\":\n            try:\n                import ollama\n\n                return ollama.Client()\n            except ImportError as e:\n                raise ImportError(\n                    \"ollama package required. Install with: pip install ollama\"\n                ) from e\n        else:\n            raise ValueError(f\"Unknown provider: {self.llm_config.provider}\")\n\n    def _init_proxy_client(self) -> Any:\n        \"\"\"Initialize an OpenAI client pointing at the Headroom proxy.\"\"\"\n        import openai\n\n        return openai.OpenAI(\n            base_url=f\"{self.llm_config.headroom_proxy_url}/v1\",\n            api_key=os.environ.get(\"OPENAI_API_KEY\", \"\"),\n        )\n\n    def _call_llm_via_proxy(self, context: str, query: str) -> str:\n        \"\"\"Call LLM through Headroom proxy (full stack: compression + CCR).\"\"\"\n        prompt = f\"\"\"Based on the following context, answer the question.\n","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/evals/runners/before_after.py#L105-L141","documentation":"Raised by BeforeAfterRunner._init_llm_client when llm_config.provider == 'ollama' but the ollama Python client is not importable. The eval runner only imports the SDK inside this branch, so an environment without 'pip install ollama' fails at the first ground-truth judge call. Everything else in the run (compression stats, proxy calls) can have succeeded before this fires.","triggerScenarios":"provider='ollama' in the LLM judge config while the ollama package is missing; or the package is installed but the Ollama server itself is not running (that produces a connection error later, not this one).","commonSituations":"Local LLM evaluation setups where the Ollama desktop app is installed but the pip client never was; remote-eval environments expecting an Ollama endpoint; switching a suite from openai to ollama without updating dependencies.","solutions":["python -m pip install ollama.","Confirm an Ollama server is reachable (OLLAMA_HOST, default http://localhost:11434) and has pulled the judge model — otherwise you will trade this error for a connection error.","If ollama was installed into another env, re-run inside the correct venv (which python -> which pip).","Prefer installing the repo's eval extras so provider SDKs are pinned."],"exampleFix":"# before\n# provider=\"ollama\" without the client package -> ImportError\n\n# after\n$ python -m pip install ollama\n$ ollama pull llama3.1   # ensure judge model exists locally","handlingStrategy":"validation","validationCode":"import importlib.util, os, urllib.request\n\nassert importlib.util.find_spec(\"ollama\"), \"pip install ollama\"\n# server check: a connection error is the *next* failure you'd hit\ntry:\n    urllib.request.urlopen(os.environ.get(\"OLLAMA_HOST\", \"http://localhost:11434\"), timeout=2)\nexcept OSError:\n    raise SystemExit(\"Ollama server not reachable\")","typeGuard":null,"tryCatchPattern":"try:\n    runner.run()\nexcept ImportError as e:\n    if \"ollama package required\" in str(e):\n        sys.exit(\"pip install ollama and start the Ollama server\")\n    raise","preventionTips":["pip install ollama together with any local-LLM eval config.","Health-check the Ollama server and pre-pull the judge model before running suites.","Document which provider each suite file needs so environments can be provisioned accordingly."],"tags":["ollama","import-error","optional-dependency","evals","local-llm"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}