繁体   English   中英

使用py2exe处理动态导入

[英]Handling dynamic import with py2exe

我在使用py2exe为我的应用程序准备.exe时遇到问题。 此问题的根源是我创建的以下函数,用于使用动态定义的模块中的类。

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)

当我尝试使用以下方法加载某些类时:

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

运行.exe时,我最终得到以下错误:

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

我应该确切地说france.model.data.py确实存在。

处理这个问题的适当方法是什么?

有关信息,请访问安装文件: https//github.com/openfisca/openfisca/blob/dev/src/setup_x64.py

我有类似的设置

确保在py2exe的“packages”部分添加动态模块

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM