|
使用pyinstaller打包多个py文件,main.py是主文件,其它是附属文件,上位机需要需要连接串口接收数据,使用打包命令如下:
yinstaller main.py -p BlockGraphData.py -p Calibrater.py -p design.py -p EngineView.py -p MavlinkData.py -p ParamMaps.py -p ParamView.py -p Plotter.py -p PowerAdjust.py -p utils.py
在dist会有一个main.exe文件,点击运行可以显示页面,当点击串口连接后,会先进行时间同步,时间同步完成之后就闪退了,错误提示如下图:
提示:RuntimeError:failed to load svg image driver
然后继续找代码,发现在python库中site-packages\pkg_resources\__init__.py代码中的“init_imagedrawers()”函数出了问题,
def create(_format, filename, **kwargs):
if len(drawers) == 0:
print('mytest drawers:\r\n',drawers)
print('myget is:\r\n',kwargs.get('debug'))
init_imagedrawers(debug=kwargs.get('debug'))
在运行creat函数会调用init_imagedrawers函数
def init_imagedrawers(debug=False):
print('init_imagedrawers\r\n')
print('mytest4:\r\n',pkg_resources.iter_entry_points('blockdiag_imagedrawers'))
for drawer in pkg_resources.iter_entry_points('blockdiag_imagedrawers'):
try:
module = drawer.load()
print('myload is:\r\n',module)
print('hasattr is\r\n',hasattr(module, 'setup'))
if hasattr(module, 'setup'):
module.setup(module)
except Exception as exc:
print('Exception\r\n')
if debug:
warning('Failed to load %s: %r' % (drawer.module_name, exc))
里面的print函数是我添加的,其余代码未改变。正常情况下,for循环会得到执行,但是打包成exe完成后,for循环未进入,for循环的print语句都没有打出数据,导致后面出错。试了很久,drawers={},kwargs.get('debug')的值是None,运行打包的exe文件就是进入不了for循环,导致后面出错。求大神赐教!
|
-
上位机闪退报错
|