{"record":{"id":"ed5730caba4818a7","repo":"run-llama/llama_index","slug":"please-install-rake-nltk-pip-install-rake-nltk","errorCode":null,"errorMessage":"Please install rake_nltk: `pip install rake_nltk`","messagePattern":"Please install rake_nltk: `pip install rake_nltk`","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/keyword_table/utils.py","lineNumber":37,"sourceCode":"    token_counts = Counter(tokens)\n    keywords = [keyword for keyword, count in token_counts.most_common(max_keywords)]\n    return set(keywords)\n\n\ndef rake_extract_keywords(\n    text_chunk: str,\n    max_keywords: Optional[int] = None,\n    expand_with_subtokens: bool = True,\n) -> Set[str]:\n    \"\"\"Extract keywords with RAKE.\"\"\"\n    try:\n        import nltk\n    except ImportError:\n        raise ImportError(\"Please install nltk: `pip install nltk`\")\n    try:\n        from rake_nltk import Rake\n    except ImportError:\n        raise ImportError(\"Please install rake_nltk: `pip install rake_nltk`\")\n\n    r = Rake(\n        sentence_tokenizer=nltk.tokenize.sent_tokenize,\n        word_tokenizer=nltk.tokenize.wordpunct_tokenize,\n    )\n    r.extract_keywords_from_text(text_chunk)\n    keywords = r.get_ranked_phrases()[:max_keywords]\n    if expand_with_subtokens:\n        return set(expand_tokens_with_subtokens(keywords))\n    else:\n        return set(keywords)\n\n\ndef extract_keywords_given_response(\n    response: str, lowercase: bool = True, start_token: str = \"\"\n) -> Set[str]:\n    \"\"\"\n    Extract keywords given the GPT-generated response.","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/keyword_table/utils.py#L19-L55","documentation":"After confirming nltk is present, rake_extract_keywords() lazily imports rake_nltk (the RAKE algorithm wrapper). If that second optional package is missing it raises ImportError with 'pip install rake_nltk'. Like nltk, it is only pulled in on the RAKE keyword-extraction path, so the error surfaces only when a RAKEKeywordTableIndex or retriever_mode='rake' actually runs.","triggerScenarios":"nltk installed but rake_nltk not; building RAKEKeywordTableIndex.from_documents(docs); calling KeywordTableIndex.as_retriever(retriever_mode=KeywordTableRetrieverMode.RAKE) — both paths execute rake_extract_keywords.","commonSituations":"Installing only nltk after seeing the previous error and hitting this second guard; minimal deployments of llama-index-core; lockfiles generated on machines that never exercised the RAKE path.","solutions":["pip install rake_nltk (keep nltk installed too — both are required by this function).","Add both to your dependency manifest so environments are reproducible: nltk and rake_nltk alongside llama-index-core.","Alternatively avoid RAKE entirely with SimpleKeywordTableIndex, which requires no extra packages."],"exampleFix":"# before\n# nltk installed, rake_nltk missing\nindex = RAKEKeywordTableIndex.from_documents(docs)  # ImportError\n\n# after\npip install nltk rake_nltk\nindex = RAKEKeywordTableIndex.from_documents(docs)","handlingStrategy":"validation","validationCode":"import importlib.util\n\nfor mod in (\"nltk\", \"rake_nltk\"):\n    assert importlib.util.find_spec(mod) is not None, f\"missing {mod}: pip install {mod}\"","typeGuard":null,"tryCatchPattern":"try:\n    index = RAKEKeywordTableIndex.from_documents(docs)\nexcept ImportError as e:\n    if \"rake_nltk\" in str(e):\n        index = SimpleKeywordTableIndex.from_documents(docs)\n    else:\n        raise","preventionTips":["Install nltk AND rake_nltk together — the check is sequential and both are needed.","Put optional extras in requirements/lockfiles, not ad-hoc pip installs.","Add a startup dependency probe for optional features your app uses."],"tags":["llama-index","rake","rake-nltk","optional-dependency","import"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}