youtube_dl 给出 AttributeError (python) [英] youtube_dl giving AttributeError (python)

查看:27
本文介绍了youtube_dl 给出 AttributeError (python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

from __future__ import unicode_literals
import youtube_dl


ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])

我几乎从 在 python 脚本中使用 youtube-dl 仅从 youtube 视频下载音频.出现的错误是:

I pretty much copied this from download only audio from youtube video using youtube-dl in python script. The error that is coming up is:

AttributeError: module 'youtube_dl' has no attribute 'YoutubeDL'

我做了很多研究,但似乎 youtube_dl 是一个非常不常见的模块.从本质上讲,它可以从 youtube 上获取大量数据.我的代码应该成功地从我想要的 youtube 链接中获取音频.然而,同样的错误总是出现.我在 python 2.7.13 和 3.6.3 上运行它 - 两者的结果相同.它似乎对其他人有效,还有另一个关于此的主题 这里 有人能告诉我是什么导致了错误,以便我可以继续这个项目吗?

I did lots of research but is seems youtube_dl is a pretty uncommon module. Essentially, it can get a ton of data off of youtube. The code I had was supposed to successfully grab audio from a youtube link of my desire. However, that same error always comes up. I ran it on python 2.7.13 and 3.6.3 - the same outcome on both. It seemed to have worked for otthers, and there was another thread about this here Can someone tell me what is causing the error so I can move onward with this project?

推荐答案

如果您将文件命名为 youtube_dl.py,它会混淆程序的思想.顺便说一句,我在您的代码中没有看到任何问题.

If you have named your file as youtube_dl.py, It will mix the programs mind. I am not seeing any problem in your code btw.

这篇关于youtube_dl 给出 AttributeError (python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆