TypeError:应为str、字节或os.PathLike对象,而不是木槌中的_io.BufferedReader



我在这里学习了mallet的教程https://www.youtube.com/watch?v=TgXLq1XIdA0&t=823s。然而,我在运行python脚本后收到了这个错误。

Traceback (most recent call last):
File "tm.py", line 38, in <module> 
lda_model = gensim.models.wrappers.ldamallet.LdaMallet(
File "C:Usersmmbanaconda3libsite-packagesgensimmodelswrappersldamallet.py", line 126, in __init__
self.train(corpus)
File "C:Usersmmbanaconda3libsite-packagesgensimmodelswrappersldamallet.py", line 279, in train
self.word_topics = self.load_word_topics()
File "C:Usersmmbanaconda3libsite-packagesgensimmodelswrappersldamallet.py", line 337, in load_word_topics
with utils.smart_open(self.fstate()) as fin:
File "C:Usersmmbanaconda3libsite-packagessmart_opensmart_open_lib.py", line 138, in smart_open
return file_smart_open(parsed_uri.uri_path, mode)
File "C:Usersmmbanaconda3libsite-packagessmart_opensmart_open_lib.py", line 642, in file_smart_open
return compression_wrapper(open(fname, mode), fname, mode)
File "C:Usersmmbanaconda3libsite-packagessmart_opensmart_open_lib.py", line 630, in compression_wrapper
return make_closing(GzipFile)(file_obj, mode)
File "C:Usersmmbanaconda3libgzip.py", line 173, in __init__
fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
TypeError: expected str, bytes or os.PathLike object, not _io.BufferedReader

错误发生在创建lda_mallet模型的过程中。

mallet_path = os.path.join('C:mallet','bin','mallet')
# create the mallet modeling object
lda_model = gensim.models.wrappers.ldamallet.LdaMallet(
mallet_path,
corpus=processed_corpus,
id2word=corpus_dictionary,
num_topics=number_of_topics,
optimize_interval=10,
prefix='fed_'
)

我修复了自己的错误。我在anaconda中创建了一个新环境,并安装了gensim和其他必需的库。它有效!

相关内容

  • 没有找到相关文章

最新更新