You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Visual Studio中使用Whisper与Pytube时遇TypeError问题求助

问题描述

尝试使用Whisper转写YouTube视频音频,代码如下:

import pytube
import whisper

youtubeUrl = "https://www.youtube.com/watch?v=a419iZMeN0o&ab_channel=SinEmbargoAlAire"
youtubeVideo = pytube.YouTube(youtubeUrl)

audio = youtubeVideo.streams.get_audio_only()
audio.download(filename='tmp.mp4')

model = whisper.load_model("small")
result = model.transcribe('tmp.mp4')

print(result['text'])

运行代码后终端报错:

PS C:\Users\fenix.vscode> &C:/Users/fenix/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/fenix/.vscode/import pytube.py"
Traceback (most recent call last):
File "c:\Users\fenix.vscode\import pytube.py", line 2, in
import whisper File "C:\Users\fenix\AppData\Local\Programs\Python\Python310\lib\site-packages\whisper.py", line 69, in
libc = ctypes.CDLL(libc_name) File "C:\Users\fenix\AppData\Local\Programs\Python\Python310\lib\ctypes_init_.py", line 364, in init
if '/' in name or '' in name: TypeError: argument of type 'NoneType' is not iterable

已安装Whisper、Pytube及Git示例要求的ffmpeg,无法定位问题。

解决办法
  • 安装官方版Whisper:错误根源是安装了非OpenAI官方的同名whisper包,导致依赖缺失。执行以下命令重装:

    pip uninstall whisper -y
    pip install git+https://github.com/openai/whisper.git
    
  • 清理冲突文件:检查Python的site-packages目录,确保删除所有非官方的whisper.py或whisper文件夹,避免导入混淆。

  • 验证ffmpeg环境变量:打开终端输入ffmpeg -version,若无法输出版本,将ffmpeg安装路径添加到系统PATH环境变量,重启终端和VS Code后重试。

  • 重命名代码文件:当前代码文件名import pytube.py可能与模块导入逻辑冲突,建议改为youtube_transcribe.py这类无歧义的名称。

内容的提问来源于stack exchange,提问作者Jesus Garcia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 03:25:20