起步
第一次用 Whisper 时,我照着官方 README 搭环境,本以为几条命令搞定,结果踩了几个小坑。写下来给后来者提个醒。
系统方面,Whisper 支持 Windows、macOS 和 Linux。Python 版本建议 3.8 到 3.11,我用的 3.10。PyTorch 会跟着 Whisper 自动装,但提前了解怎么装 CPU/GPU 版能省不少事。内存 4G 以上就行,有 NVIDIA 显卡最好,没有也能用 CPU 慢慢跑。
安装 Python
去Python 官网下载对应版本。Windows 安装时一定勾上'Add Python to PATH',免得后续敲路径。macOS 装 .pkg,一路下一步。Linux 就用包管理器:
sudo apt update && sudo apt install python3 python3-pip # Ubuntu/Debian
装完检查一下版本:
python --version
pip --version
能正常显示版本就 ok。我习惯用 venv 隔离环境,后头细说。
装 PyTorch
Whisper 跑在 PyTorch 上,所以得先装。官方的安装指导页会根据你的系统生成命令。
没 GPU 或者图省事,直接装 CPU 版:
pip3 install torch torchvision torchaudio
有 NVIDIA 显卡的话,留意 CUDA 版本。我手头的机器 CUDA 11.8,所以用:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
如果你装的 CUDA 12.1,把链接里的 cu118 换成 cu121。
验证一下有没有装对:
import torch
print(torch.__version__)
print(torch.cuda.is_available())
第二行 True 就说明 GPU 能用了;False 就是只跑 CPU。
装 Whisper
最省心的方式是用 pip:
pip install -U openai-whisper
想追最新功能,直接从 GitHub 仓库拉:
pip install git+https://github.com/openai/whisper.git
如果之前装过,更新时可能会遇到依赖冲突,加 --force-reinstall 强装一把:
pip install --upgrade --no-deps --force-reinstall git+https://github.com/openai/whisper.git
配置 FFmpeg
Whisper 处理音频需要 FFmpeg,而且必须能在命令行直接调用。也就是说,得把它的可执行文件路径加到 PATH 里。
Windows 用户去 gyan.dev 下载 build,解压后把 文件夹路径加到系统环境变量。macOS 用 Homebrew 一条搞定:

