在python应用程序中使用了pubsub,使用工具调试的运行一切正常,但是使用pyinstaller 将程序打包成exe文件后,出现如下错误。
Traceback (most recent call last):
File "upload_test_run_dynamic_clean.py", line 21, in
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 File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
ImportError: No module named publisher
然后在查看pyinstaller工具将程序打包的过程中出现的日志文件发现有一个地方出现错误日志
INFO: Loading module hook "hook-wx.lib.pubsub.py"...
Traceback (most recent call last):
File "" , line 41, in <module>
File "" , line 36, in walk_packages
File "" , 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中的文件
将kwargs中相关的文件拷贝到core目录下面,然后使用pyinstaller重新生成exe重新
参考资料:https://wiki.wxpython.org/WxLibPubSub