&quot'attributeError:部分初始化的模块' pytube'没有属性' YouTube' (最有可能是由于循环进口)。

发布于 2025-01-25 02:51:50 字数 538 浏览 3 评论 0 原文

这是代码:

import pytube as p
video_url = input("Enter the link: ")
youtube = p.YouTube(video_url)
filters = youtube.streams.filter(progressive=True, file_extension="mp4")
filters.get_highest_resolution().download("MyPath")

我尝试编写一个代码以下载YouTube视频。但这是一个错误的说法:

attributeError:部分初始化的模块'pytube'没有属性“ youtube”(最有可能是由于圆形导入引起的)

“完整错误消息”

我什至从Internet复制了Pasted代码pytube,但没有任何作用。更令人沮丧的是,几个月前我执行它时的工作正常。

Here is the code:

import pytube as p
video_url = input("Enter the link: ")
youtube = p.YouTube(video_url)
filters = youtube.streams.filter(progressive=True, file_extension="mp4")
filters.get_highest_resolution().download("MyPath")

I tried to write a code to download a YouTube video. But it's throwing an error saying:

AttributeError: partially initialized module 'pytube' has no attribute 'YouTube' (most likely due to a circular import)`

full error message

I even copy-pasted codes from the internet, re-installed Python, and re-installed pytube but none worked. What's even more frustrating is, that it was working fine when I executed it a few months before.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻想少年梦 2025-02-01 02:51:50

attributeError:部分初始化的模块'pytube'没有属性“ youtube”(很可能是由于圆形导入引起的)

您是否注意到您的文件是如何命名的? pytube.py 。这可能导致 循环>循环导入 ,因为Python试图导入 pytube.py 文件本身。


我建议您阅读 this /代码> ,第一个正是您的情况。


因此,简短的答案是:

更改您的文件名!

当我说更改时,我的意思是您必须重命名您的文件,而不是创建新文件。

AttributeError: partially initialized module 'pytube' has no attribute 'YouTube' (most likely due to a circular import)

Did you notice how is your file named? pytube.py. This may have caused the circular import, since Python is trying to import the pytube.py file itself.


I would suggest you to read this and this, the first one is exactly your case.


So the short answer is:

Change your file name!

And when I say change I mean that you have to rename your file, and not to create a new one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文