{"record":{"id":"c4b665c469c194dc","repo":"headroomlabs-ai/headroom","slug":"mem0-package-not-installed-install-with-pip-inst-c4b665","errorCode":null,"errorMessage":"mem0 package not installed. Install with: pip install 'headroom-ai[memory-stack]'","messagePattern":"mem0 package not installed\\. Install with: pip install 'headroom-ai\\[memory-stack\\]'","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"headroom/memory/backends/mem0.py","lineNumber":126,"sourceCode":"        \"\"\"\n        self._config = config or Mem0Config()\n        self._client: Any = None\n        self._initialized = False\n\n    async def _ensure_client(self) -> Any:\n        \"\"\"Ensure Mem0 client is initialized.\n\n        Returns:\n            The initialized Mem0 Memory client.\n\n        Raises:\n            ImportError: If mem0 package is not installed.\n        \"\"\"\n        if self._client is None:\n            try:\n                from mem0 import Memory as Mem0Memory\n            except ImportError:\n                raise ImportError(\n                    \"mem0 package not installed. Install with: pip install 'headroom-ai[memory-stack]'\"\n                ) from None\n\n            if self._config.mode == \"cloud\":\n                if not self._config.api_key:\n                    raise ValueError(\"api_key is required for cloud mode\")\n                # Cloud mode - use API key\n                self._client = await asyncio.to_thread(Mem0Memory, api_key=self._config.api_key)\n            else:\n                # Local mode with configuration\n                qdrant_provider_cfg: dict[str, Any] = {\n                    \"collection_name\": self._config.collection_name,\n                }\n                if self._config.qdrant_url:\n                    qdrant_provider_cfg[\"url\"] = self._config.qdrant_url\n                else:\n                    qdrant_provider_cfg[\"host\"] = self._config.qdrant_host\n                    qdrant_provider_cfg[\"port\"] = self._config.qdrant_port","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/memory/backends/mem0.py#L108-L144","documentation":"Raised by Mem0Backend._ensure_client() when 'from mem0 import Memory' fails. Unlike the direct adapter (222), this is the standard mem0 backend wrapper; it initializes its client lazily on the first operation and only needs the mem0 package (cloud or local mode), not the full memory-stack.","triggerScenarios":"Constructing Mem0Backend with a Mem0Config and issuing the first save/search call; the lazy _ensure_client() hits the ImportError and re-raises with the extra name.","commonSituations":"Installing headroom-ai core without extras; CI pipelines trimming optional deps; using mem0 cloud mode where developers assume no local packages are needed but the SDK is still required.","solutions":["pip install 'headroom-ai[memory-stack]'","Or the minimal fix: pip install mem0ai","Verify in the app venv: python -c 'from mem0 import Memory'","Consider the sqlite/local backend if you want zero external packages"],"exampleFix":"# before\nbackend = Mem0Backend(Mem0Config(mode='cloud', api_key=...))\nawait backend.save('note')  # ImportError: mem0 package not installed\n\n# after\npip install 'headroom-ai[memory-stack]'\nawait backend.save('note')","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec('mem0') is None:\n    raise SystemExit('mem0 required for Mem0Backend; pip install \"headroom-ai[memory-stack]\"')","typeGuard":null,"tryCatchPattern":"try:\n    await backend.save('note')\nexcept ImportError as e:\n    if 'mem0 package not installed' in str(e):\n        # degrade gracefully to a local backend if available\n        backend = make_local_backend()\n    else:\n        raise","preventionTips":["Declare the memory-stack extra in your project's dependencies when using Mem0Backend","Probe optional imports at startup and pick a fallback backend deliberately","Add an import smoke test to CI"],"tags":["python","import","dependency","mem0","memory-backend"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}