python - TypeError:预期的 str、字节或 os.PathLike 对象,而不是槌中的 _io.BufferedReader
问题描述
我按照这里的槌子教程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:\Users\mmb\anaconda3\lib\site-packages\gensim\models\wrappers\ldamallet.py", line 126, in __init__
self.train(corpus)
File "C:\Users\mmb\anaconda3\lib\site-packages\gensim\models\wrappers\ldamallet.py", line 279, in train
self.word_topics = self.load_word_topics()
File "C:\Users\mmb\anaconda3\lib\site-packages\gensim\models\wrappers\ldamallet.py", line 337, in load_word_topics
with utils.smart_open(self.fstate()) as fin:
File "C:\Users\mmb\anaconda3\lib\site-packages\smart_open\smart_open_lib.py", line 138, in smart_open
return file_smart_open(parsed_uri.uri_path, mode)
File "C:\Users\mmb\anaconda3\lib\site-packages\smart_open\smart_open_lib.py", line 642, in file_smart_open
return compression_wrapper(open(fname, mode), fname, mode)
File "C:\Users\mmb\anaconda3\lib\site-packages\smart_open\smart_open_lib.py", line 630, in compression_wrapper
return make_closing(GzipFile)(file_obj, mode)
File "C:\Users\mmb\anaconda3\lib\gzip.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 和其他所需的库。有用!
推荐阅读
- flutter - 颤振的证书固定
- r - 如何从更大的组中随机抽取具有多行的子组?
- oozie - Oozie - 仅今天时间的协调员
- flutter - 用于创建手机身份验证凭据的短信验证码无效
- c# - 如何避免 C# 中的多个条件
- excel - Excel vba - 是否可以在没有组框的情况下使选项按钮独立
- python - Kivy 中具有推送和弹出矩阵的多个自定义小部件
- typescript - 搜索表单更改时如何在打字稿中打印内容?
- python - Python - Windows Raw Disk 无法读取最终扇区
- amazon-web-services - EventBridge PutEvents 基于标签的策略