How to fix this pytube NameError in python?

Viewed 81

I'm just a beginner (@^0^@)/ help me please (ToT)/~~~

Here is my code:

from pytube import YouTube

from pytube import Playlist

##print("Enter PLAYLIST URL lnot privatel")

url=input("PLAYLIST URL: ")

pl=pytube.Playlist(url)

pl.streams.filter(only_audio).download_all(r'C:\Users\+USERNAME+\Music')

exit()

And here is my error:

== RESTART: C:\Youtube Downloader\mp3 playlist.py ==
URL: +PLAYLIST URL+
Traceback (most recent call last):
  File "C:\Youtube Downloader\mp3 playlist.py", line 5, in <module>
    pl=pytube.Playlist(url)
NameError: name 'pytube' is not defined
>>> 
2 Answers

You use from pytube import something, that means it is imported from the module, and you don't need to specify it explicitly. Do:

pl=Playlist(url)

You've already imported Playlist from pytube.

Try to change:

pl=pytube.Playlist(url)

into:

pl=Playlist(url)
Related