Question

I have a problem when preparing an .exe for my app using py2exe. The source of this problem is the following function that I created to use classes from a dynamically defined module.

def of_import(module, classname, country = None):
    '''
    Returns country specific class found in country module
    '''
    if country is None:
       country = CONF.get('simulation', 'country')
    _temp = __import__(country + '.' + module, 
                       globals = globals(), 
                       locals = locals(), 
                       fromlist = [classname], 
                       level=-1)
    return getattr(_temp, classname, None)

When I try to load some class using:

self.InputTable = of_import('model.data', 'InputTable')

I end up with the following error when running the .exe:

File "core\utils.pyc", line 900, in of_import
ImportError: No module named france.model.data

I should precise that the france.model.data.py do exist.

What would be the appropriate way to deal with this issue ?

For information here is the link to the setup file : https://github.com/openfisca/openfisca/blob/dev/src/setup_x64.py

Was it helpful?

Solution

I have a similar setup

Make sure you add your dynamic modules in the "packages" section of py2exe

setup(windows=[{
                "script" : "openFisca.pyw"
                }], 
      options={"py2exe" : {"includes" : ["sip", "encodings.*", "numpy.*"],
                           "packages": ["france","tunisia"],
                           "dist_dir": dist_dir,
                           "bundle_files":3,
                           "dll_excludes": ["MSVCP90.dll"]
                           }}, 
      data_files=data_files)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top