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

使用pytube时IDE提示YouTube类get_videos属性未解析如何解决?

Fixing the "unresolved attribute reference 'get_videos' for 'YouTube'" Error in Pytube

Hey there! That error pops up because the get_videos() method was deprecated and completely removed in newer versions of pytube (11.0.0 and above). The pytube team replaced it with a more flexible streams API that gives you better control over video/audio formats and resolutions. Let me walk you through the fix step by step:

Why This Happens

The old get_videos() method was phased out to make way for the streams system, which supports modern YouTube streaming features (like separate audio/video streams for higher quality, adaptive bitrates, etc.). IDEs flag the error because the method no longer exists in the current pytube class structure.

The Proper Fix: Use the streams API

Here's how to rewrite your code to work with modern pytube:

  1. Get all available streams (includes video-only, audio-only, and combined video-audio streams):

    from pytube import YouTube
    
    link = "your_video_url_here"
    yt = YouTube(link)
    # Access all streams associated with the video
    all_streams = yt.streams
    
  2. Filter for video streams (tailor results to your needs):

    • If you want streams that include both video and audio (called "progressive" streams, perfect for direct download without merging):
      progressive_video_streams = yt.streams.filter(progressive=True)
      # List available options to pick from
      for stream in progressive_video_streams:
          print(f"Resolution: {stream.resolution}, Format: {stream.mime_type}, Itag: {stream.itag}")
      
    • If you want all video streams (including higher-quality ones without audio, which require merging with a separate audio stream later):
      video_only_streams = yt.streams.filter(type="video")
      
  3. Download your chosen stream
    Once you've picked a stream (via resolution or itag), download it with one line:

    # Download the highest-resolution progressive stream
    yt.streams.get_highest_resolution().download()
    
    # Or download a specific stream using its itag
    yt.streams.get_by_itag(22).download() # Itag 22 typically refers to 720p MP4 with audio
    

If you need to keep using get_videos() for legacy code, you can install an older pytube version where the method still exists:

pip install pytube==10.8.0

Note: This isn't ideal—older versions may have bugs, security gaps, and won't support YouTube's latest updates. Migrating to the streams API is the better long-term solution.

内容的提问来源于stack exchange,提问作者shweta jaiswal

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:23:41