Windows pyinstaller wxPython pyecharts无法正常显示问题

Windows pyinstaller wxPython pyecharts无法正常显示问题

最近遇到一个pyinstaller打包wxPython pyecharts无法显示的问题,pyecharts生成的html页面显示空白。未使用pyinstaller打包时显示正常。

问题原因

WebViewBackendDefault = b'' WebViewBackendEdge = b'wxWebViewEdge' WebViewBackendIE = b'wxWebViewIE' WebViewBackendWebKit = b'wxWebViewWebKit' WebViewDefaultURLStr = b'about:blank' 

在windows环境非打包情况下使用wxPythonwx.html2.WebView.New()使用的是WebViewBackendEdge的引擎,WebViewBackendEdgeChrome用的是同一个内核所以能正常显示。 而通过pyinstaller打包后pyinstaller找不到对应的配置文件,无法使用WebViewBackendEdge的引擎,所以默认打包的浏览器是IE,而pyecharts默认使用的是最新版本的echarts链接,IE不支持新版本的echarts的特性,导致页面无法显示的问题

方案一

  • 指定低版本的echarts版本,使用低于3.7.0的版本
from pyecharts.globals import CurrentConfig  CurrentConfig.ONLINE_HOST = "https://cdn.jsdelivr.net/npm/echarts@3.6.2/dist/" 

方案二

  • pyinstaller打包时指定打包文件, 下面提供两种方法,二选一即可

    1. 命令行增加

       # 增加这个  --add-binary "{HOMEPATH}/wx/WebView2Loader.dll:."  
    2. 配置文件xxx.spec增加

      # -*- mode: python ; coding: utf-8 -*- from PyInstaller import HOMEPATH  a = Analysis( 	...     # 增加这个     binaries=[(f'{HOMEPATH}/wx/WebView2Loader.dll', '.')], 	... ) 
  • 完整配置文件xxx.spec

    # -*- mode: python ; coding: utf-8 -*- from PyInstaller import HOMEPATH  a = Analysis(     ['main.py'],     pathex=[],     binaries=[(f'{HOMEPATH}/wx/WebView2Loader.dll', '.')],     datas=[('./static/datasets', 'pyecharts/datasets/'), ('./static/templates', 'pyecharts/render/templates/'), ('./static/js', 'static/js/')],     hiddenimports=[],     hookspath=[],     hooksconfig={},     runtime_hooks=[],     excludes=[],     noarchive=False,     optimize=0, ) pyz = PYZ(a.pure)  exe = EXE(     pyz,     a.scripts,     a.binaries,     a.datas,     [],     name='mini-tool',     debug=False,     bootloader_ignore_signals=False,     strip=False,     upx=True,     upx_exclude=[],     runtime_tmpdir=None,     console=False,     disable_windowed_traceback=False,     argv_emulation=False,     target_arch=None,     codesign_identity=None,     entitlements_file=None,     icon=['static\icon.png','static\icon.png'], )  
发表评论

评论已关闭。

相关文章