1

I have been searching this forum and many others and cannot seem to get a good method of creating an executable. I have tried several different methods (py2exe, pyinstaller and cx_freeze) and all seem to give me some kind of error.

When i tried pyinstaller, I received the error that "no _imaging C module is installed". Everything I search says that it has to do with PIL, but my code is not using PIL.

When I tried py2exe, I keep receiving the following error:

File "Scout_Tool.py", line 18, in <module>
File "matplotlib\pyplot.pyc", line 95, in <module>
File "matplotlib\backends\__init__.pyc", line 25, in pylab_setup
ImportError: No module named backend_qt4agg

I am at a loss of what to do. My code contains the following imports:

import os
import csv
import wx
import time
import math

from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.pyplot import figure,show
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from numpy.random import rand
from datetime import datetime
import wx.calendar as cal
import numpy as npy
from pylab import *
import numpy as np
import matplotlib
import adodbapi
import sqlparse
import pylab
import annote_new
import cPickle as pickle

Does anyone have any suggestions on how to do a build of the executable using py2exe? What i have tried...

from distutils.core import setup 
import py2exe 
import matplotlib 

setup( 
    windows=[{'script': r'Scout_Tool.py'}], 

    data_files=matplotlib.get_py2exe_datafiles(), 

    options={
        r'py2exe': {
            r'includes': r'ElementConfig', 
            r'includes': r'ColorConv', 
            r'includes': r'Tkinter', 
            r'includes': r're', 
            r'includes': r'math', 
            r'includes': r'sys', 
            r'includes': r'matplotlib', 
            r'includes': r'mpl_toolkits',
            r'includes': r'matplotlib.backends.backend_wx',
            r'dll_excludes': [r'MSVCP90.dll'], 
        }
    }, 

) 

Thanks for any help!

jdi
  • 90,542
  • 19
  • 167
  • 203
mcfly
  • 1,151
  • 4
  • 33
  • 55
  • PIL is most likely used within matplotlib. It may be having trouble finding the dependencies of your libs. Have you tried explicitly adding the modules that it complains about to your include list? – jdi Jun 27 '12 at 17:28
  • Do you have an example? Based on my error above, i added "r'includes': r'matplotlib.backends.backend_qt4agg'," to my include list but it didn't seem to do anything – mcfly Jun 27 '12 at 17:37

1 Answers1

3

I am not fully sure this will fix your problem, but you should start by correcting that faulty options dictionary entry. In python, when you define a dictionary with the same key over and over, you are only going to get the last value. A key can only exist once:

options={
    r'py2exe': {
        r'includes': r'ElementConfig', 
        ...
        r'includes': r'mpl_toolkits',
        r'includes': r'matplotlib.backends.backend_wx',
        ...
    }
} 

print options
#{'py2exe': {'includes': 'matplotlib.backends.backend_wx'}}

I suspect the result of this usage is py2exe not really finding any of your intended includes. includes should be a list:

options={
    'py2exe':{
        'includes': [
            'ElementConfig',
            'ColorConv',
            'Tkinter',
            're',
            'math',
            'sys',
            'matplotlib',
            'mpl_toolkits',
            'matplotlib.backends.backend_wx'
        ],
        'dll_excludes': ['MSVCP90.dll'], 
    }
},

If after this, it still complains about the backend missing, you can add another explicit entry:

        'includes': [
            ...
            'matplotlib.backends.backend_qt4agg'
        ],
jdi
  • 90,542
  • 19
  • 167
  • 203
  • Ok, I got pass the backend error. But now I'm getting this: Traceback (most recent call last): File "Scout_Tool.py", line 19, in File "mpl_toolkits\basemap\__init__.pyc", line 30, in File "mpl_toolkits\basemap\pyproj.pyc", line 63, in IOError: proj data directory not found. Expecting it at: C:\Python27\dist\library.zip\mpl_toolkits\basemap\data – mcfly Jun 27 '12 at 18:01
  • That part probably has to do with the matplot specific `get_py2exe_datafiles` thing. I don't have any experience bundling matplot, so I'm not really sure. Have you tried the extensive examples here: http://www.py2exe.org/index.cgi/MatPlotLib ? – jdi Jun 27 '12 at 18:08