PyInstaller打包CefPython项目出现ICU数据无效文件描述符错误
PyInstaller打包CefPython程序时的ICU数据错误问题
环境配置(64位)
- Windows 11
- Python 3.9.13
- PyInstaller 5.7.0
- wxPython 4.2.0
- CefPython 66.1
问题现象
直接执行python BuildTest.py时程序运行完全正常,但通过pyinstaller BuildTest.spec打包生成BuildTest.exe后,程序无法启动,报错信息为:
"ERROR:icu_util.cc(133) Invalid file descriptor to ICU data received."
已尝试的11种解决方案(均无效)
- 修改BuildTest.spec中的
hookspath=[ ]为hookspath=['.']或hookspath=['.', 'C:\copied cefpython resource path'] - 在项目根目录替换
hook-cefpython3.py,将Python2相关代码改为is_py2 = None - 将CefPython所有资源复制到项目根目录
- 开启
debug=True构建spec文件,未发现错误 - 修改cef_setting并开启
debug=True,构建过程无错误 - 将Python版本从3.9降级到3.8,再到3.7
- 在Python3.7环境下搭配使用CefPython 66.0版本
- 安装Microsoft SDK/Visual C++ Build tool 14、CMake工具
- 移除csv、json等非核心Python包
- 检查并打印cef_setting相关路径,BuildTest.py运行时路径均正常
- 重启计算机
相关代码
BuildTest.py
from cefpython3 import cefpython as cef import sys # chrome_folder 为Chrome_resources文件夹路径 chrome_folder = "你的资源路径" # 注:原代码未定义该变量,需自行补充 version = "你的版本号" # 注:原代码未定义该变量,需自行补充 cef_setting = { "context_menu": {"enabled": False}, "multi_threaded_message_loop": False, "browser_subprocess_path": f"{chrome_folder}\\subprocess.exe", "resources_dir_path": chrome_folder, "user_data_path": f"{chrome_folder}\\user_data", "locales_dir_path": f"{chrome_folder}\\locales", "cache_path": f"{chrome_folder}\\caches", # 韩语本地化配置 "locale": "ko.pak", "command_line_args_disabled": True, "downloads_enabled": False, "ignore_certificate_errors": True, "javascript_flags": "--js-flags", "product_version": version, "remote_debugging_port": -1, "debug": True, } sys.excepthook = cef.ExceptHook # 仅BuildTest.exe会在此代码处触发ICU错误 cef.Initialize(cef_setting, None) APP().MainLoop()
BuildTest.spec
#-*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis( ['BuildTest.py'], pathex=[], binaries=[], datas=[], hiddenimports=[], hookspath=['.'], hooksconfig={}, runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False, ) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE( pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], name='BuildTest', debug=True, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=True, disable_windowed_traceback=False, argv_emulation=False, target_arch=None, codesign_identity=None, entitlements_file=None, )
Debug模式运行BuildTest.exe的日志
[8240] PyInstaller Bootloader 5.x [8240] LOADER: executable is E:\Python\python39\BuildTest.exe [8240] LOADER: homepath is E:\Python\python39 [8240] LOADER: _MEIPASS2 is NULL [8240] LOADER: archivename is E:\Python\python39\BuildTest.exe [8240] LOADER: Cookie found at offset 0x79AE927 [8240] LOADER: Extracting binaries [8240] LOADER: creating directory C:\Users\Username\AppData\Local\Temp\_MEI82402 with security string: D:(A;;FA;;;S-1-5-21-3853376492-3040409701-2110696266-1003) [8240] LOADER: creating directory C:\Users\Username\AppData\Local\Temp\_MEI82402\cefpython3 with security string: D:(A;;FA;;;S-1-5-21-3853376492-3040409701-2110696266-1003) [8240] LOADER: creating directory C:\Users\Username\AppData\Local\Temp\_MEI82402\pywin32_system32 with security string: D:(A;;FA;;;S-1-5-21-3853376492-3040409701-2110696266-1003) [8240] LOADER: creating directory C:\Users\Username\AppData\Local\Temp\_MEI82402\wx with security string: D:(A;;FA;;;S-1-5-21-3853376492-3040409701-2110696266-1003) [8240] LOADER: creating directory C:\Users\Username\AppData\Local\Temp\_MEI82402\locales with security string: D:(A;;FA;;;S-1-5-21-3853376492-3040409701-2110696266-1003) [8240] LOADER: creating directory C:\Users\Username\AppData\Local\Temp\_MEI82402\swiftshader with security string: D:(A;;FA;;;S-1-5-21-3853376492-3040409701-2110696266-1003) [8240] LOADER: Executing self as child [8240] LOADER: set _MEIPASS2 to C:\Users\Username\AppData\Local\Temp\_MEI82402 [8240] LOADER: Setting up to run child [8240] LOADER: Creating child process [8240] LOADER: Waiting for child process to finish... [3824] PyInstaller Bootloader 5.x [3824] LOADER: executable is E:\Python\python39\BuildTest.exe [3824] LOADER: homepath is E:\Python\python39 [3824] LOADER: _MEIPASS2 is C:\Users\Username\AppData\Local\Temp\_MEI82402 [3824] LOADER: archivename is E:\Python\python39\BuildTest.exe [3824] LOADER: Cookie found at offset 0x79AE927 [3824] LOADER: SetDllDirectory(C:\Users\Username\AppData\Local\Temp\_MEI82402) [3824] LOADER: Already in the child - running user's code. [3824] LOADER: ucrtbase.dll found: C:\Users\Username\AppData\Local\Temp\_MEI82402\ucrtbase.dll [3824] LOADER: Python library: C:\Users\Username\AppData\Local\Temp\_MEI82402\python39.dll [3824] LOADER: Loaded functions from Python library. [3824] LOADER: Manipulating environment (sys.path, sys.prefix) [3824] LOADER: sys.prefix is C:\Users\Username\AppData\Local\Temp\_MEI82402 [3824] LOADER: Pre-init sys.path is C:\Users\Username\AppData\Local\Temp\_MEI82402\base_library.zip;C:\Users\Username\AppData\Local\Temp\_MEI82402\lib-dynload;C:\Users\Username\AppData\Local\Temp\_MEI82402 [3824] LOADER: Setting runtime options [3824] LOADER: Initializing python [3824] LOADER: Overriding Python's sys.path [3824] LOADER: Post-init sys.path is C:\Users\Username\AppData\Local\Temp\_MEI82402\base_library.zip;C:\Users\Username\AppData\Local\Temp\_MEI82402\lib-dynload;C:\Users\Username\AppData\Local\Temp\_MEI82402 [3824] LOADER: Setting sys.argv [3824] LOADER: setting sys._MEIPASS [3824] LOADER: importing modules from CArchive [3824] LOADER: extracted struct [3824] LOADER: running unmarshalled code object for struct... [3824] LOADER: extracted pyimod01_archive [3824] LOADER: running unmarshalled code object for pyimod01_archive... [3824] LOADER: extracted pyimod02_importers [3824] LOADER: running unmarshalled code object for pyimod02_importers... [3824] LOADER: extracted pyimod03_ctypes [3824] LOADER: running unmarshalled code object for pyimod03_ctypes... [3824] LOADER: extracted pyimod04_pywin32 [3824] LOADER: running unmarshalled code object for pyimod04_pywin32... [3824] LOADER: Installing PYZ archive with Python modules. [3824] LOADER: PYZ archive: PYZ-00.pyz [3824] LOADER: Running pyiboot01_bootstrap.py [3824] LOADER: Running pyi_rth_inspect.py [3824] LOADER: Running BuildTest.py [0118/211649.807:ERROR:icu_util.cc(133)] Invalid file descriptor to ICU data received.
内容的提问来源于stack exchange,提问作者JH Bok
相关产品推荐
相关产品推荐

