title: Python pickle: ImportError: No module named __main__
body: <p>Hi I have a 2 very simple programs that are being run on two computers. Which pickle and unpickle a class.</p>
  
  <p>On one computer (using Linux):</p>
  
  <pre><code>import cPickle
  
  # Define class
  class test():
      def __init__():
          self.foo = 1
  
  # Initialise and pickle class
  bar = test()
  with open("test.pkl", "wb") as file_:
      cPickle.dump(bar, file_, protocol=0)
  </code></pre>
  
  <p>On the second computer (using Windows):</p>
  
  <pre><code>import cPickle
  
  # Define class again
  class test():
      def __init__():
          self.foo = 1 
  
  # Unpickle file
  with open("test.pkl", "rb") as file_:
      bar = cPickle.dump(file_)
  </code></pre>
  
  <p>But I get an error:</p>
  
  <pre><code>ImportError: No module named __main__
  </code></pre>
  
  <p>One machine is using windows, another is using Linux and the script and pickle are being transferred using GIT (version control system). I cant understand why this is occurring as the class is defined directly in the main in both scripts.</p>