{"record":{"id":"f2423d1ddb39bd74","repo":"mem0ai/mem0","slug":"the-anthropic-library-is-required-please-instal","errorCode":null,"errorMessage":"The 'anthropic' library is required. Please install it using 'pip install anthropic'.","messagePattern":"The 'anthropic' library is required\\. Please install it using 'pip install anthropic'\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"mem0/llms/anthropic.py","lineNumber":7,"sourceCode":"import os\nfrom typing import Dict, List, Optional, Union\n\ntry:\n    import anthropic\nexcept ImportError:\n    raise ImportError(\"The 'anthropic' library is required. Please install it using 'pip install anthropic'.\")\n\nfrom mem0.configs.llms.anthropic import AnthropicConfig\nfrom mem0.configs.llms.base import BaseLlmConfig\nfrom mem0.llms.base import LLMBase\n\n\nclass AnthropicLLM(LLMBase):\n    def __init__(self, config: Optional[Union[BaseLlmConfig, AnthropicConfig, Dict]] = None):\n        # Convert to AnthropicConfig if needed\n        if config is None:\n            config = AnthropicConfig()\n        elif isinstance(config, dict):\n            config = AnthropicConfig(**config)\n        elif isinstance(config, BaseLlmConfig) and not isinstance(config, AnthropicConfig):\n            # Convert BaseLlmConfig to AnthropicConfig\n            config = AnthropicConfig(\n                model=config.model,\n                temperature=config.temperature,","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/llms/anthropic.py#L1-L25","documentation":"Module-level ImportError raised when mem0/llms/anthropic.py is imported without the `anthropic` package installed. Import happens lazily when mem0 instantiates AnthropicLLM (llm provider 'anthropic'), so the error surfaces at Memory creation or first config load, not at pip install time.","triggerScenarios":"Setting llm.provider to anthropic in config without pip install anthropic; deploying mem0 in a slim container with only core deps; CI lockfile missing the optional dependency.","commonSituations":"Trying Claude models after only installing mem0ai base; venv mismatch where anthropic is installed in a different interpreter; dependency conflicts (anthropic pinned/removed by another package).","solutions":["pip install anthropic (or add mem0ai[anthropic]-style extras / declare anthropic in requirements)","Confirm the install is in the same environment: python -m pip install anthropic using the interpreter that runs mem0","Verify with python -c \"import anthropic; print(anthropic.__version__)\"","If it still fails, check for a local file/dir named anthropic.py shadowing the package"],"exampleFix":"// before\nMemory.from_config({\"llm\": {\"provider\": \"anthropic\", \"config\": {\"model\": \"claude-sonnet-4-5\"}}})  # ImportError\n\n# after\n# pip install anthropic\nMemory.from_config({\"llm\": {\"provider\": \"anthropic\", \"config\": {\"model\": \"claude-sonnet-4-5\", \"api_key\": \"...\"}}})","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec(\"anthropic\") is None:\n    raise SystemExit(\"Missing dependency: pip install anthropic\")","typeGuard":null,"tryCatchPattern":"try:\n    from mem0.llms.anthropic import AnthropicLLM\nexcept ImportError as e:\n    raise SystemExit(f\"{e}; install with: pip install anthropic\") from e","preventionTips":["Declare anthropic in requirements when llm.provider is anthropic","Add a startup smoke test that imports every configured provider","Beware file shadowing: never name a local module anthropic.py"],"tags":["python","anthropic","import-error","dependencies","mem0"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}