mem0ai/mem0 · error · RuntimeError

Failed to download spaCy model en_core_web_sm: {e}. Please i

Error message

Failed to download spaCy model en_core_web_sm: {e}. Please install manually: python -m spacy download en_core_web_sm

What it means

Raised by _ensure_model_available in mem0.utils.spacy_models when spaCy is installed but the en_core_web_sm model is missing and the automatic spacy.cli.download('en_core_web_sm') attempt raised (network error, no wheel for your Python version, no write access to the model directory). The original exception is chained via 'from e', so the cause is preserved.

Source

Thrown at mem0/utils/spacy_models.py:38

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():
    """Return spaCy model with all pipelines (NER, tagger, etc.) for entity extraction."""
    global _nlp_full, _load_failed_full
    if _load_failed_full:
        return None
    if _nlp_full is not None:
        return _nlp_full
    with _lock:
        if _nlp_full is not None:
            return _nlp_full
        if _load_failed_full:
            return None
        try:

View on GitHub (pinned to 001c235229)

Solutions

  1. Pre-install the model manually in the image/venv: python -m spacy download en_core_web_sm
  2. If offline: pip install the model wheel directly from https://github.com/explosion/spacy-models/releases (e.g. en_core_web_sm-3.x.x-py3-none-any.whl)
  3. Check the chained exception for the real cause (DNS/TLS/404) and fix network/proxy accordingly
  4. Bake the model into the Docker layer during build, not at runtime

Example fix

# before: RuntimeError: Failed to download spaCy model en_core_web_sm ...
from mem0 import Memory

# after (in Dockerfile)
# RUN pip install spacy && python -m spacy download en_core_web_sm
from mem0 import Memory
Defensive patterns

Strategy: try-catch

Validate before calling

import spacy
if not spacy.util.is_package('en_core_web_sm'):
    offline = not network_available()  # your check
    if offline:
        raise ConfigError('pre-install en_core_web_sm: python -m spacy download en_core_web_sm')

Try / catch

try:
    from mem0.utils.spacy_models import get_nlp_full
    nlp = get_nlp_full()
except RuntimeError as e:
    if 'Failed to download spaCy model' in str(e):
        log.error('bake en_core_web_sm into the image; see chained cause')
        raise
    raise

Prevention

When it happens

Trigger: Air-gapped or proxied environments where the model download from GitHub releases is blocked; a Python version (e.g. 3.13 pre-release) with no published en_core_web_sm wheel; read-only site-packages; corporate TLS interception breaking the download.

Common situations: Docker builds with restricted egress; CI sandboxes; offline deployments where the model was never baked into the image; pip install --user environments without write permissions.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/554ec64af72894b2. Report an issue: GitHub.