PyInstaller打包的Whisper语音转文字应用.exe加载模型时静默崩溃求助
我最近开发了一个基于faster_whisper的语音转文字工具,在PyCharm本地运行时一切正常,但用PyInstaller打包成单目录exe后,程序加载Whisper模型的环节直接静默崩溃,连异常捕获的日志都打不出来,实在头大😅
问题细节
模型加载的核心代码片段如下:
try: print(f"This gets printed") model = WhisperModel(model_source_path, device="cpu", compute_type="int8") print(f"But this does not get printed.") except Exception as e: print(f"Error loading model: {e}") print("This also never gets printed.") exit()
运行打包后的WhisperApp.exe时,控制台仅输出:
Loading Whisper model from local path: 'C:\Users\Olenb\PycharmProjects\Accessability\dist\WhisperApp\_internal\models\base'... This gets printed
然后cmd窗口直接关闭,没有任何错误提示,except块里的内容完全没机会输出。我已经确认模型的本地路径是正确的,打包后模型文件也确实在指定目录中。
我使用的PyInstaller打包命令
这是我参考AI建议生成的打包命令:
pyinstaller --onedir --name "WhisperApp" --collect-all faster_whisper --collect-all CTranslate2 --collect-all onnxruntime --hidden-import pygame --add-data "models/*;models" --add-data "RecordingSound.mp3;." "Whisper.py"
打包过程中的关键警告
执行打包命令时,控制台弹出了几个可能相关的警告:
1358 WARNING: collect_data_files - skipping data collection for module 'CTranslate2' as it is not a package.
1358 WARNING: collect_dynamic_libs - skipping library collection for module 'CTranslate2' as it is not a package.
282 WARNING: Failed to collect submodules for 'onnxruntime.quantization' because importing 'onnxruntime.quantization' raised: ModuleNotFoundError: No module named 'onnx'
环境信息
- 操作系统:Windows 10
- 核心依赖:
faster_whisper、CTranslate2、onnxruntime、pygame
有没有大佬遇到过类似的问题?或者能给点排查方向的?比如会不会是动态库没打包全,或者模型加载时的底层依赖缺失导致的无提示崩溃?




