解决 Python Whisper PyTorch DLL 加载失败问题

问题描述

在 Windows 上使用 Python 3.14 运行 openai-whisper 时遇到以下错误:

1
2
OSError: [WinError 1114] 动态链接库(DLL)初始化例程失败。
Error loading "c10.dll" or one of its dependencies.

问题原因

  1. Python 版本过新:Python 3.14 与 PyTorch 的兼容性问题
  2. DLL 依赖冲突:PyTorch 的 c10.dll 在 Windows 上加载失败
  3. 缺少 VC++ 运行库:某些情况下缺少 Visual C++ Redistributable

解决方案

方案一:切换到 faster-whisper(推荐)

faster-whisper 是 OpenAI Whisper 的重新实现,使用 CTranslate2 而非 PyTorch:

1
2
3
4
5
# 卸载有问题的包
pip uninstall openai-whisper torch torchvision

# 安装 faster-whisper
pip install faster-whisper

代码使用示例

1
2
3
4
5
6
7
8
9
from faster_whisper import WhisperModel

# 加载模型(CPU 模式)
model = WhisperModel('base', device='cpu', compute_type='int8')

# 转录音频
segments, info = model.transcribe('audio.wav')
for segment in segments:
print(f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}")

优势

  • 无需 PyTorch,避免 DLL 问题
  • 速度更快,内存占用更小
  • API 与原版类似,迁移成本低

方案二:重新安装 PyTorch CPU 版本

1
2
pip uninstall torch torchvision
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu

方案三:安装 Visual C++ Redistributable

下载安装:https://aka.ms/vs/17/release/vc_redist.x64.exe

虚拟环境注意事项

如果项目使用虚拟环境(venv),确保在正确的环境中安装:

1
2
3
4
5
# 激活 venv
venv\Scripts\activate

# 安装 faster-whisper
pip install faster-whisper

总结

对于 Windows 用户使用 Whisper 进行语音识别,faster-whisper 是更好的选择

特性 openai-whisper faster-whisper
依赖 PyTorch(重量级) CTranslate2(轻量)
速度 较慢 更快
内存 较高 更低
DLL 问题 常见

经验教训:在 Windows 上使用 Python 机器学习库时,优先选择不依赖 PyTorch/TensorFlow 的轻量级实现。


相关项目Video Prompt Analyzer