FileNotFoundError:[错误2]没有这样的文件或目录:槌路径

时间:2019-04-02 17:43:16

标签: python windows file path mallet

所以这段代码在现在起作用了,我现在收到此错误-请帮助:(

mallet_path = 'C:/mallet/mallet-2.0.8/bin/mallet.bat'

ldamallet_test = gensim.models.wrappers.LdaMallet(mallet_path, corpus=bow_corpus_test, num_topics=20, id2word=dictionary_test)

Error message

This mallet.bat file I'm referencing no longer opens

1 个答案:

答案 0 :(得分:1)

这是因为未正确设置Mallet的主目录。即使您将二进制集的路径设置为变量,也仍然必须定义包含Mallet所在源的环境变量:

import os
from gensim.models.wrappers import LdaMallet

os.environ['MALLET_HOME'] = 'C:\\mallet\\mallet-2.0.8'

mallet_path = 'C:\\mallet\\mallet-2.0.8\\bin\\mallet'
ldamallet_test = gensim.models.wrappers.LdaMallet(mallet_path, corpus=bow_corpus_test, num_topics=20, id2word=dictionary_test)

请注意,您不需要添加.bat扩展名,因为Windows知道它是一个批处理文件,因此应本机执行。最后一点,对于Windows中的路径分隔符,应使用双反斜杠(\\)。根据所使用的Windows版本不执行此操作可能会导致意外的行为。如果您想避免头痛,请尝试使用os.path.join,它将为您提供正确的路径分隔符,而与操作系统无关:

mallet_path = os.path.join('C:', 'mallet', 'mallet-2.0.8', 'bin', 'mallet')