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

使用pytube遇ImportError及HTTP Error 410,求解决方法

pytube 常见错误及解决方案

错误1:ImportError: 无法从pytube导入Youtube

问题代码

from pytube import Youtube
from sys import argv

link = input("put the link input:")
yt = Youtube[link]

print("Title: ", yt.Title)

yd = yt.streams.get_highest_resolution()

yd.download(r'C:\Users\adam6\OneDrive\Desktop\video')

错误提示

ImportError: cannot import name 'Youtube' from 'pytube' (C:\Users\adam\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube_init_.py)

已完成的排查操作

  • 确认C:\Users\adam\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube目录下存在__init__.py文件
  • 执行pip install pytube3 --upgrade,返回依赖已满足:
PS C:\Users\adam> pip install pytube3 --upgrade                                               
Requirement already satisfied: pytube3 in c:\users\adam\appdata\local\programs\python\python310\lib\site-packages (9.6.4)
Requirement already satisfied: typing-extensions in c:\users\adam\appdata\local\programs\python\python310\lib\site-packages (from pytube3) (4.3.0)
  • 运行环境:Visual Studio Code,Python版本3.10.6
PS C:\Users\adam\OneDrive\Desktop\study\python> python --version
Python 3.10.6

错误2:urllib.error.HTTPError: HTTP Error 410: Gone

修正类名拼写后,代码如下:

from pytube import YouTube
from sys import argv

link = argv[1]
yt = YouTube(link)

yd = yt.streams.get_highest_resolution()

yd.download(r'C:/Users/adam/OneDrive/Desktop/video')

运行后出现错误:

urllib.error.HTTPError: HTTP Error 410: Gone


解决方案

针对错误1的修复

pytube官方定义的类名为**YouTube**(首字母大写,末尾为大写E),而非Youtube,属于拼写错误。同时注意两处细节:

  1. 实例化类必须使用圆括号(),而非方括号[],正确写法:yt = YouTube(link)
  2. 获取视频标题的属性为小写的yt.title,而非yt.Title

针对错误2的修复

HTTP 410错误意味着请求的资源已被永久移除,根源是pytube3版本过旧(9.6.4为2020年版本),无法适配YouTube当前的页面结构和反爬机制。修复步骤:

  1. 卸载旧版本:
pip uninstall -y pytube3 pytube
  1. 安装官方维护的最新版pytube:
pip install pytube --upgrade
  1. 若官方版仍存在适配问题,可直接安装GitHub上的最新修复分支:
pip install git+https://github.com/pytube/pytube.git
  1. 路径格式优化:Windows系统下,文件路径建议使用正斜杠/或双反斜杠\\,避免转义字符引发的问题。

内容的提问来源于stack exchange,提问作者Adi S

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 10:36:52