在python應用程序中使用了pubsub,使用工具調試的運行一切正常,可是使用pyinstaller 將程序打包成exe文件後,出現以下錯誤。python
Traceback (most recent call last): File "upload_test_run_dynamic_clean.py", line 21, in <module> from wx.lib.pubsub import pub File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.__dict__) File "site-packages\wx-3.0-msw\wx\lib\pubsub\pub.py", line 35, in <module> File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module ImportError: No module named publisher
而後在查看pyinstaller工具將程序打包的過程當中出現的日誌文件發現有一個地方出現錯誤日誌app
INFO: Loading module hook "hook-wx.lib.pubsub.py"... Traceback (most recent call last): File "<string>", line 41, in <module> File "<string>", line 36, in walk_packages File "<string>", line 20, in walk_packages File "c:\python27\lib\site-packages\wx-3.0-msw\wx\lib\pubsub\core\arg1\__init__.py", line 16, in <module> raise RuntimeError(msg)RuntimeError: Should not import this directly, used by pubsub.core if applicable 8006 WARNING: Hidden import "wx.lib.pubsub.core.publisher" not found! 8008 WARNING: Hidden import "wx.lib.pubsub.core.listenerimpl" not found! 8009 WARNING: Hidden import "wx.lib.pubsub.core.publishermixin" not found! 8009 WARNING: Hidden import "wx.lib.pubsub.core.datamsg" not found! 8009 WARNING: Hidden import "wx.lib.pubsub.core.topicargspecimpl" not found! 8009 WARNING: Hidden import "wx.lib.pubsub.core.topicmgrimpl" not found!
說沒有找到pubsub相關的庫文件,可是到庫安裝的目錄下看,wx.lib.pubsub.core目錄下確實沒有這幾個文件,這幾個文件都在wx.lib.pubsub.core.kwargs/wx.lib.pubsub.core.arg1目錄下。工具
當wxPython >= 2.8.11.0, 使用kwargs中目錄的文件
其餘版本使用arg1中的文件this
將kwargs中相關的文件拷貝到core目錄下面,而後使用pyinstaller從新生成exe從新