{"record":{"id":"22bf81fbfaa4561d","repo":"mem0ai/mem0","slug":"spacy-is-not-installed-install-it-with-pip-insta","errorCode":null,"errorMessage":"spaCy is not installed. Install it with: pip install mem0ai[nlp]","messagePattern":"spaCy is not installed\\. Install it with: pip install mem0ai\\[nlp\\]","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"mem0/utils/spacy_models.py","lineNumber":26,"sourceCode":"\nimport logging\nimport threading\n\nlogger = logging.getLogger(__name__)\n\n_nlp_full = None\n_nlp_lemma = None\n_load_failed_full = False\n_load_failed_lemma = False\n_lock = threading.Lock()\n\n\ndef _ensure_model_available():\n    \"\"\"Download en_core_web_sm if spaCy is installed but model is missing.\"\"\"\n    try:\n        import spacy\n    except ImportError:\n        raise ImportError(\n            \"spaCy is not installed. Install it with: pip install mem0ai[nlp]\"\n        )\n\n    if not spacy.util.is_package(\"en_core_web_sm\"):\n        logger.info(\"Downloading spaCy model en_core_web_sm...\")\n        try:\n            from spacy.cli import download\n\n            download(\"en_core_web_sm\")\n            logger.info(\"spaCy model en_core_web_sm downloaded successfully\")\n        except Exception as e:\n            raise RuntimeError(\n                f\"Failed to download spaCy model en_core_web_sm: {e}. \"\n                \"Please install manually: python -m spacy download en_core_web_sm\"\n            ) from e\n\n\ndef get_nlp_full():","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/utils/spacy_models.py#L8-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before: ImportError: spaCy is not installed ...\nfrom mem0 import Memory\nm = Memory.from_config(cfg_with_nlp)\n\n# after\n# pip install 'mem0ai[nlp]'\nfrom mem0 import Memory\nm = Memory.from_config(cfg_with_nlp)","handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec('spacy') is None:\n    raise ConfigError('spaCy missing — pip install \"mem0ai[nlp]\" before enabling NLP processing')","typeGuard":null,"tryCatchPattern":"try:\n    from mem0.utils.spacy_models import get_nlp_full\n    nlp = get_nlp_full()\nexcept ImportError as e:\n    if 'spaCy is not installed' in str(e):\n        raise ConfigError('install mem0ai[nlp] extra') from e\n    raise","preventionTips":["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"],"tags":["dependencies","spacy","nlp","installation"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}