title: Python:: IOError: [Errno 2] No such file or directory: 'models/dictionary.dict'
body: <p>I am using gensim package for topic modelling in python.</p>
  
  <p>I am trying to train the topic model using gensim. Below is the train.py module:</p>
  
  <pre><code>class Corpus(object):
      def __init__(self, cursor, reviews_dictionary, corpus_path):
          self.cursor = cursor
          self.reviews_dictionary = reviews_dictionary
          self.corpus_path = corpus_path
  
      def __iter__(self):
          self.cursor.rewind()
          for review in self.cursor:
              yield self.reviews_dictionary.doc2bow(review["words"])
  
      def serialize(self):
          BleiCorpus.serialize(self.corpus_path, self, id2word=self.reviews_dictionary)
  
          return self
  
  
  class Dictionary(object):
      def __init__(self, cursor, dictionary_path):
          self.cursor = cursor
          self.dictionary_path = dictionary_path
  
      def build(self):
          self.cursor.rewind()
          dictionary = corpora.Dictionary(review["words"] for review in self.cursor)
          dictionary.filter_extremes(keep_n=10000)
          dictionary.compactify()
          corpora.Dictionary.save(dictionary, self.dictionary_path)
  
          return dictionary
  
  
  class Train:
      def __init__(self):
          pass
  
      @staticmethod
      def run(lda_model_path, corpus_path, num_topics, id2word):
          corpus = corpora.BleiCorpus(corpus_path)
          lda = gensim.models.LdaModel(corpus, num_topics=num_topics, id2word=id2word)
          lda.save(lda_model_path)
  
          return lda
  </code></pre>
  
  <p>I am getting the below error when I run this module:</p>
  
  <pre><code>&gt; Traceback (most recent call last):
  
  
      File "train.py", line 74, in &lt;module&gt;
      main()
  
      File "train.py", line 68, in main
      dictionary = Dictionary(reviews_cursor, dictionary_path).build()
      File "train.py", line 38, in build
      corpora.Dictionary.save(dictionary, self.dictionary_path)
      File "/usr/local/lib/python2.7/dist-packages/gensim/utils.py", line 288, in save
      pickle(self, fname)
      File "/usr/local/lib/python2.7/dist-packages/gensim/utils.py", line 666, in pickle
      with smart_open(fname, 'wb') as fout: # 'b' for binary, needed on Windows
      File "/usr/local/lib/python2.7/dist-packages/gensim/utils.py", line 661, in smart_open
      return open(fname, mode)
      IOError: [Errno 2] No such file or directory: 'models/dictionary.dict'
  </code></pre>
  
  <p>Could anyone please help me figure out the issue?</p>