mem0ai/mem0 · error · ImportError
The 'anthropic' library is required. Please install it using
Error message
The 'anthropic' library is required. Please install it using 'pip install anthropic'.
What it means
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.
Source
Thrown at mem0/llms/anthropic.py:7
import os
from typing import Dict, List, Optional, Union
try:
import anthropic
except ImportError:
raise ImportError("The 'anthropic' library is required. Please install it using 'pip install anthropic'.")
from mem0.configs.llms.anthropic import AnthropicConfig
from mem0.configs.llms.base import BaseLlmConfig
from mem0.llms.base import LLMBase
class AnthropicLLM(LLMBase):
def __init__(self, config: Optional[Union[BaseLlmConfig, AnthropicConfig, Dict]] = None):
# Convert to AnthropicConfig if needed
if config is None:
config = AnthropicConfig()
elif isinstance(config, dict):
config = AnthropicConfig(**config)
elif isinstance(config, BaseLlmConfig) and not isinstance(config, AnthropicConfig):
# Convert BaseLlmConfig to AnthropicConfig
config = AnthropicConfig(
model=config.model,
temperature=config.temperature,View on GitHub (pinned to 001c235229)
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
Example fix
// before
Memory.from_config({"llm": {"provider": "anthropic", "config": {"model": "claude-sonnet-4-5"}}}) # ImportError
# after
# pip install anthropic
Memory.from_config({"llm": {"provider": "anthropic", "config": {"model": "claude-sonnet-4-5", "api_key": "..."}}}) Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
if importlib.util.find_spec("anthropic") is None:
raise SystemExit("Missing dependency: pip install anthropic") Try / catch
try:
from mem0.llms.anthropic import AnthropicLLM
except ImportError as e:
raise SystemExit(f"{e}; install with: pip install anthropic") from e Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- The 'ollama' library is required. Please install it using 'p
- The 'boto3' library is required. Please install it using 'pi
- The 'upstash_vector' library is required. Please install it
- The 'boto3' library is required. Please install it using 'pi
- FastEmbed is not installed. Please install it using `pip in
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/f2423d1ddb39bd74.
Report an issue: GitHub.