Pyinstaller and import issue with wx.lib.pubsub

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

My Python GUI app, works perfectly but when I try to create an executable I tried with pyinstaller (3.3.dev0+483c819) command:

pyinstaller gui_app.py 

I get the follow issue:

7699 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! 

The executable is "successfully" created but when I launch it i get the follow error:

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     exec(bytecode, module.__dict__)   File "site-packages\wx-3.0-msw\wx\lib\pubsub\core\__init__.py", line 45, in <module> ImportError: No module named publisher 

I tried to add hookspath is the spec file (it exists a hook for wx.lib.pubsub already in pyinstaller hooks folder) but it did not work, or I did something wrong.

Is there an order to import wx and other submodules. I have this in my code

import wx import wx.lib.pubsub.setuparg1 from wx.lib.pubsub import pub import wx.lib.agw.pybusyinfo as PBI from wx.lib.scrolledpanel import ScrolledPanel 

回答1:

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! 

These modules are missing in core, move them back there in case you have misplaced the modules.



回答2:

Apparently the import of those modules is done in the subfolder kwargs, but those files actually need to be placed in the root folder.

So I just copied those files from

Lib\site-packages\wx-3.0-msw\wx\lib\pubsub\core\kwargs 

to

Lib\site-packages\wx-3.0-msw\wx\lib\pubsub\core 

and now IT WORKS!



回答3:

I ran into the same problem, which is still present after the release of pyinstaller 3.3. This is a known issue with wx.lib.pubsub and pyinstaller. See https://github.com/pyinstaller/pyinstaller/issues/1530 ; apparently imports are handled in a way that is tricky to work around. PyPubSub is a fork of the same code base, and will have the same problem. If do not want to hack the libs of the wx distribution with every release, your options include:

  • Use pyinstaller version 3.2 (3.2 crashes hard for me, so that's not encouraging)
  • Hope that it is fixed in pyinstaller 3.4 (this looks unlikely to happen)
  • Switch to PyDispatcher or another simpler pubsub library
  • Modify PyPubSub so that it loads modules in a way that is compatible with pyinstaller, and submit the PR back to the project

The path of least resistance seems to be to find a different pubsub library. I switched to blinker, which is minimal and good for smaller projects. However, also be aware that pyinstaller 3.3 does is not yet entirely stable on python 3.6. I realize this is an old question, but for any who find this question later, you may wish to try 3.5.

I've had similar problems packing cross platform where different platforms required specific versions of python and pyinstaller. Be aware that with pyinstaller there is usually one version combination that is stable, and this varies per-platform.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!