title: py2exe and numpy not getting along
body: <p>I am trying to use py2exe-0.6.9.win32 to wrap up an application that I have written in Python2.6.5 using the following object libraries with associated download file names:</p>
  
  <p>matplotlib-0.99.3.win32</p>
  
  <p><a href="http://sourceforge.net/projects/numpy/files/NumPy/1.4.1/" rel="noreferrer">numpy-1.4.1-win32</a></p>
  
  <p>scipy-0.8.0b1-win32</p>
  
  <p>wxPython2.8-win32-unicode-2.8.11.0</p>
  
  <p>I am getting error messages when I try to launch the resulting .exe file.  At the moment, the error message is related to numpy, though before that I was getting something related to matplot lib data files not loading and thus blocking the launch of my exe file.  </p>
  
  <p>Rather than post a mile of code and all the error messages, I am posting a more general question: <strong>Can anyone show me some instructions for making all of these object libraries and versions play well together using py2exe to create a working exe file?</strong></p>
  
  <p>I have been reading things that come up with google searches on the topic, but it seems like a wild goose chase in that everyone is using different versions of different things.  I can change some of the versions of some of these object libraries if that makes a difference, but I have already written 5,000 lines of code in this signal processing application, and I would prefer not to have to re-write all of it, if possible.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here is a simplified version of my code in a file called GUIdiagnostics.py that I made to test the ability of my py2exe script to import all the libraries that I need in my real application:</p>
  
  <pre><code>import time
  import wxversion
  import wx
  import csv
  import os
  import pylab as p
  from scipy import stats
  import math
  from matplotlib import *
  from numpy import *
  from pylab import *
  import scipy.signal as signal
  import scipy.optimize
  import Tkinter
  
  ID_EXIT = 130
  
  class MainWindow(wx.Frame):
      def __init__(self, parent,id,title):
          wx.Frame.__init__(self,parent,wx.ID_ANY,title, size = (500,500), style =     wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
  
          # A button
          self.button =wx.Button(self, label="Click Here", pos=(160, 120))
          self.Bind(wx.EVT_BUTTON,self.OnClick,self.button)
  
          # the combobox Control
          self.sampleList = ['first','second','third']
          self.lblhear = wx.StaticText(self, label="Choose TestID to filter:", pos=(20, 75))
          self.edithear = wx.ComboBox(self, pos=(160, 75), size=(95, -1),     choices=self.sampleList, style=wx.CB_DROPDOWN)
  
          # the progress bar
          self.progressMax = 3
          self.count = 0
          self.newStep='step '+str(self.count)
          self.dialog = None
  
          #-------Setting up the menu.
          # create a new instance of the wx.Menu() object
          filemenu = wx.Menu()
  
          # enables user to exit the program gracefully
          filemenu.Append(ID_EXIT, "E&amp;xit", "Terminate the program")
  
          #------- Creating the menu.
          # create a new instance of the wx.MenuBar() object
          menubar = wx.MenuBar()
          # add our filemenu as the first thing on this menu bar
          menubar.Append(filemenu,"&amp;File")
          # set the menubar we just created as the MenuBar for this frame
          self.SetMenuBar(menubar)
          #----- Setting menu event handler
          wx.EVT_MENU(self,ID_EXIT,self.OnExit)
  
          self.Show(True)
  
      def OnExit(self,event):
          self.Close(True)
  
      def OnClick(self,event):
          try:
              if not self.dialog:
                  self.dialog = wx.ProgressDialog("Progress in processing your data.", self.newStep,
                                              self.progressMax,
                                              style=wx.PD_CAN_ABORT
                                              | wx.PD_APP_MODAL
                                              | wx.PD_SMOOTH)
              self.count += 1
              self.newStep='Start'
              (keepGoing, skip) = self.dialog.Update(self.count,self.newStep)
              TestID = self.edithear.GetValue()
  
              self.count += 1
              self.newStep='Continue.'
              (keepGoing, skip) = self.dialog.Update(self.count,self.newStep)
              myObject=myClass(TestID)
              print myObject.description
  
              self.count += 1
              self.newStep='Finished.'
              (keepGoing, skip) = self.dialog.Update(self.count,self.newStep)
  
              self.count = 0
  
              self.dialog.Destroy()
  
          except:
              self.dialog.Destroy()
              import sys, traceback
              xc = traceback.format_exception(*sys.exc_info())
              d = wx.MessageDialog( self, ''.join(xc),"Error",wx.OK)
              d.ShowModal() # Show it
              d.Destroy() #finally destroy it when finished
  
  class myClass():
      def __init__(self,TestID):
          self.description = 'The variable name is:  '+str(TestID)+'. '
  
  app = wx.PySimpleApp()
  frame = MainWindow(None,-1,"My GUI")
  app.MainLoop()
  </code></pre>
  
  <p>Here is the code for setup.py, which is the file containing my py2exe code:</p>
  
  <pre><code>from distutils.core import setup
  import py2exe
  
  # Remove the build folder, a bit slower but ensures that build contains the latest
  import shutil
  shutil.rmtree("build", ignore_errors=True)
  
  # my setup.py is based on one generated with gui2exe, so data_files is done a bit differently
  data_files = []
  includes = []
  excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger',
          'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
          'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', 'sqlite3'
          ]
  packages = ['pytz']
  dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
              'tk84.dll']
  icon_resources = []
  bitmap_resources = []
  other_resources = []
  
  # add the mpl mpl-data folder and rc file
  import matplotlib as mpl
  data_files += mpl.get_py2exe_datafiles()
  
  setup(
      windows=['GUIdiagnostics.py'],
                        # compressed and optimize reduce the size
      options = {"py2exe": {"compressed": 2, 
                        "optimize": 2,
                        "includes": includes,
                        "excludes": excludes,
                        "packages": packages,
                        "dll_excludes": dll_excludes,
                        # using 2 to reduce number of files in dist folder
                        # using 1 is not recommended as it often does not work
                        "bundle_files": 2,
                        "dist_dir": 'dist',
                        "xref": False,
                        "skip_archive": False,
                        "ascii": False,
                        "custom_boot_script": '',
                       }
            },
  
      # using zipfile to reduce number of files in dist
      zipfile = r'lib\library.zip',
  
      data_files=data_files
  )
  </code></pre>
  
  <p>I run this code by typing the following line into the command line interface of windows (cmd.exe) as per the following link:</p>
  
  <pre><code>setup.py py2exe
  </code></pre>
  
  <p>Py2exe then runs, but when I try to launch the resulting exe file, it creates a log file containing the following message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "setup.py", line 6, in &lt;module&gt;
    File "zipextimporter.pyo", line 82, in load_module
    File "pylab.pyo", line 1, in &lt;module&gt;
    File "zipextimporter.pyo", line 82, in load_module
    File "matplotlib\pylab.pyo", line 206, in &lt;module&gt;
    File "zipextimporter.pyo", line 82, in load_module
    File "matplotlib\mpl.pyo", line 3, in &lt;module&gt;
    File "zipextimporter.pyo", line 82, in load_module
    File "matplotlib\axes.pyo", line 14, in &lt;module&gt;
    File "zipextimporter.pyo", line 82, in load_module
    File "matplotlib\collections.pyo", line 21, in &lt;module&gt;
    File "zipextimporter.pyo", line 82, in load_module
    File "matplotlib\backend_bases.pyo", line 32, in &lt;module&gt;
    File "zipextimporter.pyo", line 82, in load_module
    File "matplotlib\widgets.pyo", line 12, in &lt;module&gt;
    File "zipextimporter.pyo", line 82, in load_module
    File "matplotlib\mlab.pyo", line 388, in &lt;module&gt;
  TypeError: unsupported operand type(s) for %: 'NoneType' and 'dict'
  </code></pre>
  
  <p><strong>Can anyone show me how to edit setup.py so that py2exe can create a usable executable running numpy, scipy, matplotlib, etc.?</strong></p>
  
  <hr>
  
  <p><strong>SECOND EDIT:</strong></p>
  
  <p>OK.  I tried RC's advice again today now that I have a fresh mind for this, and I got the same errorr, but I am including it below.  Here is the code for a file called cxsetup.py that I created following the template at: <a href="http://cx-freeze.sourceforge.net/cx_Freeze.html" rel="noreferrer">http://cx-freeze.sourceforge.net/cx_Freeze.html</a> .</p>
  
  <pre><code>from cx_Freeze import setup, Executable
  
  setup(
          name = "Potark",
          version = "0.1",
          description = "My application.",
          executables = [Executable("Potark-ICG.py")])
  </code></pre>
  
  <p>Unfortunately, running it in the command line ( cmd.exe ) with the command:</p>
  
  <pre><code>python cxsetup.py build
  </code></pre>
  
  <p>generates the following error in the command line:</p>
  
  <pre><code>ImportError: No module named cx_Freeze
  </code></pre>
  
  <p>The directory in the command line is the directory for my application, which is in a subfolder of the desktop.  That is different than the directory for the python application, but I assume cmd.exe can figure that out because python can figure it out.  <strong>Am I wrong?</strong>  As a test, I added the following line of code to the first line of cxsetup.py :</p>
  
  <pre><code>import matplotlib
  </code></pre>
  
  <p>But that generated the almost identical error:</p>
  
  <pre><code>ImportError: No module named matplotlib
  </code></pre>
  
  <p>I have tried to keep this thread focused and short, but it is getting kind of long.  <strong>Can anyone help me with this?</strong>  I would hate to do all the work of switching to cx_freeze only to find that it cannot work with numpy, matplotlib, scipy, etc.</p>