簡體   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