title: How do I debug a py2exe 'application failed to initialize properly' error?
body: <p>I'm very new to Python in general, but I made an app in Python 2.6 / wxPython 2.8 that works perfectly when I run it through Python. But I wanted to go a step further and be able to deploy it as a Windows executable, so I've been trying out py2exe. But I haven't been able to get it to work. It would always compile an exe, but when I actually try to run that it barks some cryptic error message. At first they were simple messages saying it couldn't find certain DLLs, but even after giving it all the DLLs it wanted, it now returns this:</p>
  
  <pre><code>The application failed to initialize properly (0xc0000142).
  Click OK to terminate the application.
  </code></pre>
  
  <p>So I broke things down and just made a very, very simple application utilizing wxPython just to see if that would work, or if some of the more complicated features of my original app were getting in the way. But even my simple test returned the same error. Here's the code for the simple test script:</p>
  
  <pre><code>import wx
  
  class MainWindow(wx.Frame):
  
      def __init__(self, parent, id, title):
          wx.Frame.__init__(self, parent, wx.ID_ANY, title, style=wx.DEFAULT_FRAME_STYLE ^ wx.MAXIMIZE_BOX)
          panel = wx.Panel(self, -1, style = wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN | wx.FULL_REPAINT_ON_RESIZE)
          main_sizer = wx.BoxSizer(wx.VERTICAL)
  
          testtxt = wx.StaticText(panel, -1, label='This is a test!')
          main_sizer.Add(testtxt, 0, wx.ALIGN_CENTER)
  
          panel.SetSizerAndFit(main_sizer)
          self.Show(1)
          return
  
  app = wx.PySimpleApp()
  frame = MainWindow(None, -1, 'Test App')
  app.MainLoop()
  </code></pre>
  
  <p>And here's the py2exe setup script I used:</p>
  
  <pre><code>#!/usr/bin/python
  
  from distutils.core import setup
  import py2exe
  
  manifest = """
  &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;assembly xmlns="urn:schemas-microsoft-com:asm.v1"
  manifestVersion="1.0"&gt;
  &lt;assemblyIdentity
      version="0.64.1.0"
      processorArchitecture="x86"
      name="Controls"
      type="win32"
  /&gt;
  &lt;description&gt;Test Program&lt;/description&gt;
  &lt;dependency&gt;
      &lt;dependentAssembly&gt;
          &lt;assemblyIdentity
              type="win32"
              name="Microsoft.Windows.Common-Controls"
              version="6.0.0.0"
              processorArchitecture="X86"
              publicKeyToken="6595b64144ccf1df"
              language="*"
          /&gt;
      &lt;/dependentAssembly&gt;
  &lt;/dependency&gt;
  &lt;/assembly&gt;
  """
  
  setup(
      windows = [
          {
              "script": "testme.py",
              "icon_resources": [(1, "testme.ico")],
              "other_resources": [(24,1, manifest)]
          }
      ],
    data_files=["testme.ico"]
  </code></pre>
  
  <p>)</p>
  
  <p>Then I run <code>python setup.py py2exe</code>, it generates the EXE file, warns about some DLL files (which I subsequently copy into the dist directory), but then when I try to run the EXE, I get the error I quoted above immediately.</p>