python mallet LDA FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\abc\\AppData\\Local\\Temp\\d33563_state.mallet.gz'

蹲街弑〆低调 提交于 2019-12-13 03:39:49

问题


It is my first time to use mallet LDA. Basically, I downloaded the mallet-2.0.8 zip file and JDK. I installed JDK, extracted mallet-2.0.8 to a destination folder. I set the MALLET_HOME. Here is my code

mallet_path='C:/Users/abc/mallet-2.0.8/bin/mallet'
ldamallet=gensim.models.wrappers.LdaMallet(mallet_path,corpus=corpus,num_topics=20,id2word=id2word)

However, it gives the error:

FILENOTFOUNDERROR[ERROR2]

I tried

mallet_path='C:\\Users\\abc\\mallet-2.0.8\\bin\\mallet'

and

mallet_path=r'C:\Users\abc\mallet-2.0.8\bin\mallet'

I got the same error msg.


回答1:


I had the same issue and it was because I forgot to set the environment variable %MALLET_HOME%

import os
from gensim.models.wrappers import LdaMallet

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



回答2:


I was facing the same issue. The error I got was as follows:

IOError: [Errno 2] No such file or directory c:\\users\\...\\appdata\\local\\temp \\d36348_state.mallet.gz.

Each time I tried to run the code the prefix before the underscore would change but the error name would always end with the form "~Some Alphanumeric String~_state.mallet.gz".

I tried to understand the stack trace output in the console. The line just before this error line was as follows:

fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')

I googled it and found this particular link. It is a github link where a person raised a different error, but the ending part of his error log was the same as mine. The solution to his error was an upgrade of his smart_open module, which gensim depends on, as the upgrade had fixed the issue. So i checked my smart_open module version and it was 1.4.x, last updated about a year and a half ago, so I upgraded it to the version 1.5.7 and the LdaMallet code works without a hiccup.

Please check if the problem on your end is being caused because of the same reasons.

Hope it helps!

P.S. I also updated my gensim module alongside the smart_open to version 3.4.



来源:https://stackoverflow.com/questions/50671565/python-mallet-lda-filenotfounderror-errno-2-no-such-file-or-directory-c-u

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!