2

Background
I'm using cx_Freeze to build Windows and Mac packages of my application; the build executes successfully on both platforms resulting in an msi on Windows and dmg/app on Mac which I can install.

Problem
The problem occurs when I run the application on either platform. I get the error:
AttributeError: 'module' object has no attribute 'DateTime'

This is triggered by site-packages/sqlobject/col.py line 66:
DateTimeType = type(DateTime.DateTime())

I've never installed mx DateTime and have never had any trouble running the application via IDE or script but somehow bundling with cx_Freeze is changing something. I'm assuming that the import (col.py) of DateTime is getting mixed up with the import of datetime, but I'm not sure.

Workaround:
I was able to get everything working by editing col.py to set mxdatetime_available = False prior to this failed use of DateTime.DateTime() so that it never attempts to use the mxDateTime. However, modifying the underlying library source locally obviously isn't something I want to do and maintain.

Does anyone know what I might be missing here to avoid the incorrect import of the third-party library? My hack isn't a valid fix that I could submit to the SQLObject project as it removes functionality for everyone, but it shouldn't be getting into that code path to begin with and I am simply failing to see the underlying cause.

My setup.py (with a few bits removed for brevity)

import sys
from cx_Freeze import Executable, setup

cx_freeze_target = [Executable(script="main.py")]

setup_dict = dict(
    name="myapp",
    version="0.0.3",
    author="me",                
    description="An app",
    license="Undecided",
    packages=['myapp'],
    executables=cx_freeze_target
)

def main():
    setup(**setup_dict)

if __name__ == '__main__':
    main()
Alex
  • 41
  • 3

1 Answers1

1

Solution
Use the excludes build_exe option in setup.py to explicitly remove DateTime which prevents the imports in col.py from incorrectly finding them.

setup.py

import sys
from cx_Freeze import Executable, setup

cx_freeze_target = [Executable(script="main.py")]

build_options = dict(
    build_exe=dict(
        excludes=['DateTime']
    )
)

setup_dict = dict(
    name="myapp",
    version="0.0.3",
    author="me",                
    description="An app",
    license="Undecided",
    packages=['myapp'],
    executables=cx_freeze_target,
    options=build_options
)

def main():
    setup(**setup_dict)

if __name__ == '__main__':
    main()

Root Cause
From the SQLObject source it looks like it attempts to import DateTime, and if this works it assumes it is the Zope DateTime module; as I don't have MX or Zope deployed it must be another DateTime module that is being found and this does not have the same interface as these other modules, so by excluding this I avoid the invalid check.

Alex
  • 41
  • 3