mem0ai/mem0 · error · ImportError
spaCy is not installed. Install it with: pip install mem0ai[
Error message
spaCy is not installed. Install it with: pip install mem0ai[nlp]
What it means
Raised by _ensure_model_available in mem0.utils.spacy_models when spaCy itself is not importable. spaCy is an optional dependency shipped under the mem0ai[nlp] extra; the NLP-based memory processing paths call this guard before loading models, so hitting it means the NLP feature was enabled without the extra.
Source
Thrown at mem0/utils/spacy_models.py:26
import logging
import threading
logger = logging.getLogger(__name__)
_nlp_full = None
_nlp_lemma = None
_load_failed_full = False
_load_failed_lemma = False
_lock = threading.Lock()
def _ensure_model_available():
"""Download en_core_web_sm if spaCy is installed but model is missing."""
try:
import spacy
except ImportError:
raise ImportError(
"spaCy is not installed. Install it with: pip install mem0ai[nlp]"
)
if not spacy.util.is_package("en_core_web_sm"):
logger.info("Downloading spaCy model en_core_web_sm...")
try:
from spacy.cli import download
download("en_core_web_sm")
logger.info("spaCy model en_core_web_sm downloaded successfully")
except Exception as e:
raise RuntimeError(
f"Failed to download spaCy model en_core_web_sm: {e}. "
"Please install manually: python -m spacy download en_core_web_sm"
) from e
def get_nlp_full():View on GitHub (pinned to 001c235229)
Solutions
- pip install 'mem0ai[nlp]' (quotes matter in zsh; also try mem0ai[nlp,graph] if you use graph memory)
- Or install spaCy directly: pip install spacy — then the guard will download the en_core_web_sm model on first use
- For Docker: add the extra to the requirements file and rebuild
- If you do not need NLP features, disable the processing step that invokes them
Example fix
# before: ImportError: spaCy is not installed ... from mem0 import Memory m = Memory.from_config(cfg_with_nlp) # after # pip install 'mem0ai[nlp]' from mem0 import Memory m = Memory.from_config(cfg_with_nlp)
Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
if importlib.util.find_spec('spacy') is None:
raise ConfigError('spaCy missing — pip install "mem0ai[nlp]" before enabling NLP processing') Try / catch
try:
from mem0.utils.spacy_models import get_nlp_full
nlp = get_nlp_full()
except ImportError as e:
if 'spaCy is not installed' in str(e):
raise ConfigError('install mem0ai[nlp] extra') from e
raise Prevention
- Install the nlp extra whenever NLP processing is enabled: pip install 'mem0ai[nlp]'
- Keep Docker/CI images in parity with local extras
- Gate NLP features behind a config flag so minimal deployments do not import them
When it happens
Trigger: Enabling the spaCy/NLP processing features (entity extraction pipelines that call get_nlp_full/get_nlp_lemma) without installing the extra; running in a slim Docker image built from bare mem0ai; CI environments installing only core requirements.
Common situations: Upgrading mem0ai to a version that introduced NLP features while keeping the old dependency list; local dev works (global spaCy) but the deployed image fails; pip resolver skipping the extra because it was quoted wrongly.
Related errors
- The '@aws-sdk/client-bedrock-runtime' package is required to
- The '@databricks/sql' package is required to use the Databri
- Could not import reranker for provider '{provider_name}': {e
- google-auth is required for GCP authentication. Install with
- Failed to download spaCy model en_core_web_sm: {e}. Please i
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/22bf81fbfaa4561d.
Report an issue: GitHub.