Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'quote'

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 python. So I'm aspiring to something new project in python. 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()
like image 658
Sharifdeen Ashshak Avatar asked Jun 02 '20 06:06

Sharifdeen Ashshak


3 Answers

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

pip uninstall pytube
pip install pytube3
like image 132
NewPythonUser Avatar answered Nov 07 '22 08:11

NewPythonUser


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

like image 3
stevec Avatar answered Nov 07 '22 07:11

stevec


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 
like image 1
Ray Ok Avatar answered Nov 07 '22 09:11

Ray Ok