pytube / pytube

A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.
https://pytube.io
The Unlicense
12.1k stars 2.5k forks source link

ImportError: cannot import name Youtube #111

Closed JMIdeaMaker closed 7 years ago

JMIdeaMaker commented 7 years ago

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

nficano commented 7 years ago

from pytube import YouTube

Note the case on "YouTube" ;)

JMIdeaMaker commented 7 years ago

oh wow, ty

Gaju27 commented 4 years ago

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'

tr32 commented 4 years ago

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

NikunjVadsak commented 4 years ago

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 commented 4 years ago

ImportError: cannot import name 'YouTube' from partially initialized module 'pytube' (most likely due to a circular import)

help me out!!

Gaju27 commented 4 years ago

Try using https://github.com/ytdl-org/youtube-dl. this worked for me.

exciteabletom commented 3 years ago

@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.

Jonas010 commented 3 years ago

@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.

i renamed the name from my script,and the error "cannot import name 'YouTube' " still in my terminal.

exciteabletom commented 3 years ago

@Jonas010 Could you show the exact import statement you used?

saadashraf1808 commented 3 years ago

I have the exact same problem as @Jonas010. image

saadashraf1808 commented 3 years ago

image

exciteabletom commented 3 years ago

That's really strange!

If you run the same program from the terminal do you get the same error? Could be a VScode issue.

Also, make sure you have pytube3 installed instead of pytube.Maybe VSCode installed pytube instead of pytube3. It's still imported with pytube but the pip package is called pytube3.

Try pip list to see what packages you have installed.

saadashraf1808 commented 3 years ago

I have installed pytube3 so that shouldn't be the problem. How can I run the script in the terminal? Can't find how to do it on google.

exciteabletom commented 3 years ago

I'm not very familiar with Windows but you should be able to:

Let me know if that doesn't work

saadashraf1808 commented 3 years ago

when using the command prompt i get the same message when using python path\to\script.py or python3 path\to\script.py

image

exciteabletom commented 3 years ago

Damn... I really have no idea at this point, sorry.

As a last resort, you could try reinstalling pytube with python3 -m pip uninstall --user pytube3 then python3 -m pip install --user pytube3

saadashraf1808 commented 3 years ago

already tried that. you were my last hope hahaha.

exciteabletom commented 3 years ago

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!

saadashraf1808 commented 3 years ago

@exciteabletom I have found the problem, the "T" in Youtube has to be a capital. So it has to be "YouTube" and not "Youtube". Thanks a lot for your help!

ZeinabBahaa commented 3 years ago
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)
exciteabletom commented 3 years ago

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 from pytube import YouTube File "C:\Users\ZeinabBahaa\Desktop\pytube.py", line 1, in 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).

Ka141k commented 11 months ago

What helped me was renaming my files from "pytube.py" to "downloader.py"