免费资源网 – https://freexyz.cn/
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环境非打包情况下使用wxPython
的wx.html2.WebView.New()
使用的是WebViewBackendEdge
的引擎,WebViewBackendEdge
跟Chrome
用的是同一个内核所以能正常显示。 而通过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
打包时指定打包文件, 下面提供两种方法,二选一即可-
命令行增加
# 增加这个 --add-binary "{HOMEPATH}/wx/WebView2Loader.dll:."
-
配置文件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'], )
免费资源网 – https://freexyz.cn/
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)