5

I have learned basics of python, so tried this code below

from pytube import YouTube

Save_path="E:\python\youtube downloader"

link="https://www.youtube.com/watch?v=xWOoBJUqlbI"

try:
    yt=YouTube(link)

except:
    print("Connection error!")


mp4file=yt.filter('mp4')

yt.set_filename("ashshak")

d_file=yt.get(mp4files[-1].extention,mp4files[-1].resolution)

try:
    d_file.download(Save_path)

except:
    print("Error in downlaod")
    print("Download failed")

when I try this code or with GUI interface code I have given bellow, the compiler will show this error. but I have already installed "pip install pytube" library

Traceback (most recent call last):
  File "E:\python\youtube downloader\practiceyoutube.py", line 1, in <module>
    from pytube import YouTube
  File "C:\Users\PC\AppData\Local\Programs\Python\Python36\lib\site-packages\pytube\__init__.py", line 16, in <module>
    from pytube.streams import Stream
  File "C:\Users\PC\AppData\Local\Programs\Python\Python36\lib\site-packages\pytube\streams.py", line 17, in <module>
    from pytube import extract
  File "C:\Users\PC\AppData\Local\Programs\Python\Python36\lib\site-packages\pytube\extract.py", line 7, in <module>
    from pytube.compat import quote
ImportError: cannot import name 'quote'

what was the problem that I have made here. I have finished all the basic of pyhton. So I'm aspiring to something new project in pyhton. can anybody help me please?

This was the GUI code that I had used here, but make same problem here.

import tkinter as tk


from pytube import YouTube
def downloadVid():
    global E1
    string =E1.get()
    yt = YouTube(str(string))
    videos = yt.get_videos()
    s=1
    for v in videos:
        print(str(s) + '.' + str(v))
        s +=1
    n=int(input("Enter your choice"))
    vid=videos[n-1]
    destination=str(input("Enter your destination"))
    vid.download(destination)
    print(yt.filename+"\n Ha been downloaded")
root=tk.Tk()

w=tk.Label(root,text="Youtube Downloader")
w.pack()


E1=tk.Entry(root,bd=5)
E1.pack(side=tk.TOP)


button=tk.Button(root,text="Download",fg="red",command=downloadVid   )
button.pack(side=tk.BOTTOM)

root.mainloop()
stovfl
  • 13,298
  • 6
  • 18
  • 42

3 Answers3

6

I found this github issue with a possible solution: ImportError: cannot import name 'quote' from 'pytube.compat'

pip uninstall pytube
pip install pytube3
Amin Shojaei
  • 1,943
  • 1
  • 14
  • 26
NewPythonUser
  • 351
  • 1
  • 9
2

I had exactly the same error message.

I don't know enough to know why this fixes it, but I ran

pip install pytube3

Then it suddenly worked

stevec
  • 15,490
  • 6
  • 67
  • 110
0

Just had the same issue, pulling my hair out for a good few hours, solved it as above but specifically

pip uninstall pytube

pip install pytube3

and in the code

import pytube 
Suraj Rao
  • 28,186
  • 10
  • 88
  • 94
Ray Ok
  • 1