#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Salina Ks.
    Posts
    2
    Rep Power
    0

    Compiled Python App Problem


    Have created app using Python 2.5.1, wxPython 2.8.4 and BOA Constructor 0.6.1. Have used py2exe to build *.exe. All runs well except the following;

    when making a query to a MSDE database the following error occurs...

    Traceback (most recent call last):
    File "MainFrameNeedMaterial.pyo", line 1178, in OnButtonProcess
    File "MainFrameNeedMaterial.pyo", line 1325, in StartNeedMaterial
    File "getSQLOrders.pyc", line17, in GetSQLOrders
    File "zipextimport.pyo", line 98, in load_module
    RunTimeError: Unable to import decimal

    The query is as follows:

    def GetSQLOrders():

    SQLOrders = []
    import datetime
    import string
    import unicode2ascii
    import pyodbc
    connection = pyodbc.connect('Driver={SQL Server};Server=MSDESERVER\SIGMANEST;Database=LaserFabDB;UID=JonR;Pwd=grainbelt')
    c = connection.cursor()
    c.execute("select RouterID, \
    RStatus, \
    WONumber, \
    GBSText, \
    CustName, \
    DueDate, \
    MaterialID, \
    str(MatThickness,6,4) Gauge, \
    Quantity \
    from AllOrders \
    where WIP_QLeft > 0 \
    and (RStatus = 'Accepted' \
    or RStatus = 'Material') \
    or RStatus IS NULL")

    for row in c:
    #print row
    line = str(row[0]), \
    str(row[1]), \
    str(row[2]), \
    str(row[3]), \
    str(row[4]).replace(',',''), \
    str(row[5])[0:10], \
    str(row[6]), \
    str(row[7]), \
    str(row[8])

    router = str(row[0])
    status = str(row[1])
    wo = str(row[2])
    pn = str(row[3])
    customer = str(row[4])
    #...CONVERT DATE TEXT TO DATE OBJECT
    date_text = str(row[5])[0:10]
    year = int(date_text[0:4])
    month = int(date_text[5:7])
    day = int(date_text[8:10])
    date = datetime.datetime(year,month,day)
    #print type(date)
    #...CONVERT DATE TEXT TO DATE OBJECT
    material = str(row[6])
    gauge = str(row[7])
    qty = str(row[8])
    LINE = string.join(line,',')
    #print LINE
    NEWLINE = unicode2ascii.latin1_to_ascii(LINE)
    #print NEWLINE

    SQLOrders.append(NEWLINE)

    c.close()
    return SQLOrders

    #...TESTING
    #SQLOrders = GetSQLOrders()
    #for item in SQLOrders:
    # print item

    I am also including "zipextimporter.py" (edited to show line 98) as follows:

    r"""zipextimporter - an importer which can import extension modules from zipfiles

    This file and also _memimporter.pyd is part of the py2exe package.

    Overview
    ========

    zipextimporter.py contains the ZipExtImporter class which allows to
    load Python binary extension modules contained in a zip.archive,
    without unpacking them to the file system.

    Call the zipextimporter.install() function to install the import hook,
    add a zip-file containing .pyd or .dll extension modules to sys.path,
    and import them.

    It uses the _memimporter extension which uses code from Joachim
    Bauch's MemoryModule library. This library emulates the win32 api
    function LoadLibrary.

    Sample usage
    ============

    You have to prepare a zip-archive 'lib.zip' containing
    your Python's _socket.pyd for this example to work.

    >>> import zipextimporter
    >>> zipextimporter.install()
    >>> import sys
    >>> sys.path.insert(0, "lib.zip")
    >>> import _socket
    >>> print _socket
    <module '_socket' from 'lib.zip\_socket.pyd'>
    >>> _socket.__file__
    'lib.zip\\_socket.pyd'
    >>> _socket.__loader__
    <ZipExtensionImporter object 'lib.zip'>
    >>> # Reloading also works correctly:
    >>> _socket is reload(_socket)
    True
    >>>

    """
    import imp, sys
    import zipimport
    import _memimporter

    class ZipExtensionImporter(zipimport.zipimporter):
    _suffixes = [s[0] for s in imp.get_suffixes() if s[2] == imp.C_EXTENSION]

    def find_module(self, fullname, path=None):
    result = zipimport.zipimporter.find_module(self, fullname, path)
    if result:
    return result
    if fullname in ("pywintypes", "pythoncom"):
    fullname = fullname + "%d%d" % sys.version_info[:2]
    fullname = fullname.replace(".", "\\") + ".dll"
    if fullname in self._files:
    return self
    else:
    fullname = fullname.replace(".", "\\")
    for s in self._suffixes:
    if (fullname + s) in self._files:
    return self
    return None

    def locate_dll_image(self, name):
    # A callback function for_memimporter.import_module. Tries to
    # locate additional dlls. Returns the image as Python string,
    # or None if not found.
    if name in self._files:
    return self.get_data(name)
    return None

    def load_module(self, fullname):
    if sys.modules.has_key(fullname):
    mod = sys.modules[fullname]
    if _memimporter.get_verbose_flag():
    sys.stderr.write("import %s # previously loaded from zipfile %s\n" % (fullname, self.archive))
    return mod
    _memimporter.set_find_proc(self.locate_dll_image)
    try:
    return zipimport.zipimporter.load_module(self, fullname)
    except zipimport.ZipImportError:
    pass
    initname = "init" + fullname.split(".")[-1] # name of initfunction
    filename = fullname.replace(".", "\\")
    if filename in ("pywintypes", "pythoncom"):
    filename = filename + "%d%d" % sys.version_info[:2]
    suffixes = ('.dll',)
    else:
    suffixes = self._suffixes
    for s in suffixes:
    path = filename + s
    if path in self._files:
    if _memimporter.get_verbose_flag():
    sys.stderr.write("# found %s in zipfile %s\n" % (path, self.archive))
    code = self.get_data(path)
    (LINE #98) mod = _memimporter.import_module(code, initname, fullname, path)
    mod.__file__ = "%s\\%s" % (self.archive, path)
    mod.__loader__ = self
    if _memimporter.get_verbose_flag():
    sys.stderr.write("import %s # loaded from zipfile %s\n" % (fullname, mod.__file__))
    return mod
    raise zipimport.ZipImportError, "can't find module %s" % fullname

    def __repr__(self):
    return "<%s object %r>" % (self.__class__.__name__, self.archive)

    def install():
    "Install the zipextimporter"
    sys.path_hooks.insert(0, ZipExtensionImporter)
    sys.path_importer_cache.clear()

    ##if __name__ == "__main__":
    ## import doctest
    ## doctest.testmod()

    I've been going crazy trying to solve this issue to no avail. Does anyone have any suggestions?

    Thanks in advance for your response!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Location
    Durbanville, Cape Town
    Posts
    1
    Rep Power
    0
    Hi. Not sure if you found a solution. I contacted the pyodbc developer, since I had the same problem. He quickly helped me.
    Your setup.py that you use with py2exe needs to look something like this:

    from distutils.core import setup
    import py2exe

    setup(console = ['YourAPP.py'],
    options = {"py2exe":{"includes":"decimal"}}
    )


    His explanation was:
    "The problem is that the decimal class is loaded by pyodbc, but since
    py2exe can only examine Python code, not C++, it doesn't know this.
    You'll need to tell py2exe to include the decimal module."
    Hope this helps

IMN logo majestic logo threadwatch logo seochat tools logo