pytube: ImportError: cannot import name Youtube

Did a pip install pytube, tried import Youtube with from pytube import Youtube uninstalled and did a

git clone https://github.com/nficano/pytube.git && cd pytube
setup.py build
sudo setup.py install

still cannot import Youtube

However I did a dir(pytube) and see ‘Youtube’ there I’m not sure why I cant import it

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 23

Commits related to this issue

Most upvoted comments

I have the same ImportError. The import statement from pytube import YouTube does not work. Can not resolve module.

importError: cannot import name ‘YouTube’ from partially initialized module ‘pytube’ (most likely due to a circular import)

I am getting the same kind import error. anyone can help to resolve the same ?

@venkatkumar1810 @NikunjVadsak

The circular import error happens because you named your script pytube.py. Python prioritises modules in the working directory so you are trying to import your script pytube recursively.

Renaming the file to something else will fix this.

from pytube import YouTube

Note the case on “YouTube” 😉

Rename your file. Its called ‘pytube’ so it conflicts with the library name which is also ‘pytube’

On Aug 4, 2021 at 6:19 am, <ZeinabBahaa @.***)> wrote:

from pytube import YouTube YouTube(‘https://youtu.be/2lAe1cqCOXo’).streams.first().download() yt = YouTube(‘http://youtube.com/watch?v=2lAe1cqCOXo’) yt.streams filter(progressive=True, file_extension=‘mp4’) order_by(‘resolution’) desc() first() download()

Traceback (most recent call last): File “C:\Users\ZeinabBahaa\Desktop\pytube.py”, line 1, in <module> from pytube import YouTube File “C:\Users\ZeinabBahaa\Desktop\pytube.py”, line 1, in <module> from pytube import YouTube ImportError: cannot import name ‘YouTube’ from partially initialized module ‘pyt ube’ (most likely due to a circular import) (C:\Users\ZeinabBahaa\Desktop\pytu be.py)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub (https://github.com/pytube/pytube/issues/111#issuecomment-892204002), or unsubscribe (https://github.com/notifications/unsubscribe-auth/ANDX73YLHKVSEMD53NVQU6DT3BTP5ANCNFSM4CQ3TE6Q). Triage notifications on the go with GitHub Mobile for iOS (https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675) or Android (https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email).

Maybe open your own issue for this, someone more experienced than me might know what’s wrong. Sorry I couldn’t help, best of luck with your programming!

from pytube import YouTube yt = YouTube(‘https://www.youtube.com/watch?v=47L9HXwxiIg&t=28s’) stream = yt.streams.first() stream.download(‘C:/’)

stream.download()

from pytube import YouTube

ImportError: cannot import name ‘YouTube’ from ‘pytube’

oh wow, ty