run-llama/llama_index · error · ImportError

Spacy is not installed, please install it with `pip install

Error message

Spacy is not installed, please install it with `pip install spacy`.

What it means

Error "Spacy is not installed, please install it with `pip install spacy`." thrown in run-llama/llama_index.

Source

Thrown at llama-index-core/llama_index/core/postprocessor/node.py:46

    required_keywords: List[str] = Field(default_factory=list)
    exclude_keywords: List[str] = Field(default_factory=list)
    lang: str = Field(default="en")

    @classmethod
    def class_name(cls) -> str:
        return "KeywordNodePostprocessor"

    def _postprocess_nodes(
        self,
        nodes: List[NodeWithScore],
        query_bundle: Optional[QueryBundle] = None,
    ) -> List[NodeWithScore]:
        """Postprocess nodes."""
        try:
            import spacy
        except ImportError:
            raise ImportError(
                "Spacy is not installed, please install it with `pip install spacy`."
            )
        from spacy.matcher import PhraseMatcher

        nlp = spacy.blank(self.lang)
        required_matcher = PhraseMatcher(nlp.vocab)
        exclude_matcher = PhraseMatcher(nlp.vocab)
        required_matcher.add("RequiredKeywords", list(nlp.pipe(self.required_keywords)))
        exclude_matcher.add("ExcludeKeywords", list(nlp.pipe(self.exclude_keywords)))

        new_nodes = []
        for node_with_score in nodes:
            node = node_with_score.node
            doc = nlp(node.get_content())
            if self.required_keywords and not required_matcher(doc):
                continue
            if self.exclude_keywords and exclude_matcher(doc):
                continue

View on GitHub (pinned to afd0fef371)

Solutions

  1. Install spacy: `pip install spacy`.
  2. Download the needed spacy model, e.g. `python -m spacy download en_core_web_sm`.

When it happens

Trigger: Thrown at llama-index-core/llama_index/core/postprocessor/node.py:46 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/49b27ecb7a3cb5a8. Report an issue: GitHub.