{"record":{"id":"52fe1bc5ccbb2ae8","repo":"fxsjy/jieba","slug":"jieba-file-does-not-exist-s-52fe1b","errorCode":null,"errorMessage":"jieba: file does not exist: %s","messagePattern":"jieba: file does not exist: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"jieba/analyse/tfidf.py","lineNumber":26,"sourceCode":"_get_module_path = lambda path: os.path.normpath(os.path.join(os.getcwd(),\n                                                 os.path.dirname(__file__), path))\n_get_abs_path = jieba._get_abs_path\n\nDEFAULT_IDF = _get_module_path(\"idf.txt\")\n\n\nclass KeywordExtractor(object):\n\n    STOP_WORDS = set((\n        \"the\", \"of\", \"is\", \"and\", \"to\", \"in\", \"that\", \"we\", \"for\", \"an\", \"are\",\n        \"by\", \"be\", \"as\", \"on\", \"with\", \"can\", \"if\", \"from\", \"which\", \"you\", \"it\",\n        \"this\", \"then\", \"at\", \"have\", \"all\", \"not\", \"one\", \"has\", \"or\", \"that\"\n    ))\n\n    def set_stop_words(self, stop_words_path):\n        abs_path = _get_abs_path(stop_words_path)\n        if not os.path.isfile(abs_path):\n            raise Exception(\"jieba: file does not exist: \" + abs_path)\n        content = open(abs_path, 'rb').read().decode('utf-8')\n        for line in content.splitlines():\n            self.stop_words.add(line)\n\n    def extract_tags(self, *args, **kwargs):\n        raise NotImplementedError\n\n\nclass IDFLoader(object):\n\n    def __init__(self, idf_path=None):\n        self.path = \"\"\n        self.idf_freq = {}\n        self.median_idf = 0.0\n        if idf_path:\n            self.set_new_path(idf_path)\n\n    def set_new_path(self, new_idf_path):","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/fxsjy/jieba/blob/67fa2e36e72f69d9134b8a1037b83fbb070b9775/jieba/analyse/tfidf.py#L8-L44","documentation":"tfidf.KeywordTokenizer.set_stop_words resolves the stop-word file path and requires it to be an existing file before loading words into the stop-word set. A missing file raises Exception with the resolved absolute path. Note the file must also be UTF-8 (decoded right after this check).","triggerScenarios":"Calling jieba.analyse.set_stop_words(path) where path doesn't exist, is a directory, or a relative path resolved from the wrong working directory.","commonSituations":"Shipping keyword-extraction code without bundling the stop-words file; relative paths breaking when the process cwd changes; typo'd filenames.","solutions":["Use an absolute path anchored to your module: os.path.join(os.path.dirname(__file__), 'stopwords.txt')","Check os.path.isfile(path) before calling set_stop_words","Bundle the stop-word file as package data when distributing"],"exampleFix":"# before\njieba.analyse.set_stop_words('stop_words.txt')\n\n# after\nimport os\njieba.analyse.set_stop_words(os.path.join(os.path.dirname(__file__), 'stop_words.txt'))","handlingStrategy":"validation","validationCode":"import os\np = os.path.join(BASE_DIR, 'stopwords.txt')\nassert os.path.isfile(p) and open(p, 'rb').read().decode('utf-8')\njieba.analyse.set_stop_words(p)","typeGuard":null,"tryCatchPattern":"try:\n    jieba.analyse.set_stop_words(p)\nexcept Exception as e:\n    if 'does not exist' in str(e):\n        log.warning('stop words missing; using defaults')","preventionTips":["Ship stop-word files with the app","Use absolute paths","Keep stop-word files UTF-8"],"tags":["jieba","tfidf","stop-words","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"67fa2e36e72f69d9134b8a1037b83fbb070b9775","analyzedAt":"2026-08-27T11:28:25.101Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}