Sara
Sara

Reputation: 1202

FileNotFoundError: [Errno 2] No such file or directory: mallet path

So this code was working before now I'm getting this error - please help :(

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

Upvotes: 1

Views: 1437

Answers (1)

rayryeng
rayryeng

Reputation: 104464

This is because your home directory for Mallet is not set up properly. Even though you have the path to the binary set as a variable, you still must define the environment variable that contains the source of where Mallet is located:

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)

Take note that you don't need to add the .bat extension as Windows should execute this natively as it knows it's a batch file. As a final note, you should use double backslashes (\\) for the path separator in Windows. Not doing this depending on what version of Windows you're using may give unexpected behaviour. If you want to avoid headaches, try using os.path.join which will provide the right path separator for you regardless of the OS:

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

Upvotes: 1

Related Questions