pyinstaller+wxpython+selinum

打包了一个桌面应用

打包命令

gui.py是你桌面应用的入口文件

pyinstaller --onefile -F gui.py

会生成dist目录,该目录下有exe

为了简单,我将程序中的用到的文件目录都改为当前目录,如

yamlPath = "./conf.yml"

这个当前目录会是你执行命令的目录,你的文件(比如上面的conf.yml)要在该目录下

建议将用到的文件都拷贝到dist目录中,并在dist目录中打开cmd运行程序

 

selinum我用的火狐浏览器,把驱动拷贝到dist目录

驱动路径当时写的:

self.driver = Firefox(executable_path='./geckodriver.exe', firefox_options=self.options)  # 配了环境变量第一个参数就可以省了,不然传绝对路径

 

wxpython报了一个错误

ModuleNotFoundError: No module named 'wx.lib.pubsub.core.publisher'

你打开路径在core中确实找不到publisher

 

 打开arg1和kwargs这里面则有publisher,咋回事

你打开__init__.py,发现注释

Core package of pubsub, holding the publisher, listener, and topic
object modules. Functions defined here are used internally by
pubsub so that the right modules can be found later, based on the
selected messaging protocol.

Indeed some of the API depends on the messaging
protocol used. For instance sendMessage(), defined in publisher.py,
has a different signature (and hence implementation) for the kwargs
protocol than for the arg1 protocol.

The most convenient way to
support this is to put the parts of the package that differ based
on protocol in separate folder, and add one of those folders to
the package's __path__ variable (defined automatically by the Python
interpreter when __init__.py is executed). For instance, code
specific to the kwargs protocol goes in the kwargs folder, and code
specific to the arg1 protocol in the arg1 folder. Then when doing
"from pubsub.core import listener", the correct listener.py will be
found for the specified protocol. The default protocol is kwargs.

Only one protocol can be used in an application. The default protocol,
if none is chosen by user, is kwargs, as selected by the call to
_prependModulePath() at end of this file. 

wxpython自己会选择用哪个文件夹下的publisher

但是pyinstaller不知道,所以打包起来就报错了

我发现程序使用的是kwargs中的文件,我把kwargs中的文件拷贝到core目录下了

并在gui.py中导入

from wx.lib.pubsub.core import publisher
from wx.lib.pubsub.core import listenerimpl

这样打包后就可以运行了

 

写个一行命令的脚本,在exe的目录中打开cmd并运行gui.exe

cmd /k "cd /d %~dp0&&gui.exe"

出现了

 

posted on 2020-06-25 10:39  AI数据  阅读(314)  评论(0编辑  收藏  举报

导航