hi 各位看官,本文是截止2018年7月4日,基于python2.7開發wxpython時的打包正確用法。
坑1:
wxpython的最新版本為4.0.3 但是因為4.0.3引入了新的pubsub 4.0 不兼容python2.7。所以如果用python2.7的同學必須降級到wxpython 4.0.1版本
坑2:
打包方面,我們可以用pyinstaller打包。但是pip上,pyinstaller最新的版本是3.3.1 版本,此版本上有bug https://github.com/pyinstaller/pyinstaller/issues/2215
但是后期,pyinstall的作者修復了此bug在dev版本上,所以我們只有去github上安裝最新的dev版本才能打包成功
踩坑表現:
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 "d:\program files\python\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
出現pubsub報錯,因為wxpython 2.8.0之前的版本用的是\core\arg1\ 所以為了能順利打包,我們要進行如下操作:
填坑方法:
1.pip裝wxpython 4.0.1版本
pip install robotframework==2.8.7
2.pip裝dev版本pyinstaller
pip install git+https://github.com/pyinstaller/pyinstaller
3.重新打包主入口main.py
pyinstaller -D main.py