Reputation: 5
I need help, I got stuck with a problem inside of my python code.
I have installed pytube module from cmd with
pip install pytube
and got "succesfully installed", also installed pip install pytube3
, vs code doesnt find any error in the debbuging but when I try to run my code I got this error:
File "c:\Users\redos\OneDrive\Desktop\Progetti\Programmazione\Python\progetti\youtube.py", line 1, in <module>
from pytube import Youtube, Search
ImportError: cannot import name 'Youtube' from 'pytube' (C:\Users\redos\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__init__.py)
I also tried to do pip install pytube3 --upgrade
and pip install pytube --upgrade
and got
Requirement already satisfied: pytube3 in c:\users\redos\appdata\local\programs\python\python39\lib\site-packages (9.6.4)
Requirement already satisfied: typing-extensions in c:\users\redos\appdata\local\programs\python\python39\lib\site-packages (from pytube3) (3.10.0.0)
this is the code:
from pytube import Youtube, Search
print("================================\n What do you want to do?: ")
availableChoose = [
'1 Search videos',
'...',
'================================'
]
for choose in availableChoose:
print(choose)
userChoose = input()
userChoose = userChoose.lower()
def videoSearch():
userSearch = input("Enter the title of the video you want to search: ")
vid = Search(userSearch)
availableResults = len(vid.results)
strAvailableResults = str(availableResults)
print("The available results are " + strAvailableResults)
vidResultsList = vid.results
vidResultsList = str(vidResultsList)
vidResultsList = vidResultsList.replace("<pytube.__main__.YouTube object: videoId=", "")
vidResultsList = vidResultsList.replace(">", "")
vidResultsList = vidResultsList.replace("[", "")
vidResultsList = vidResultsList.replace("]", "")
vidResultsList = vidResultsList.replace(" ", "")
vidResultsList = vidResultsList.split(',')
for vidResultsObject in vidResultsList:
vidTempObject = ("https://www.youtube.com/watch?v=" + vidResultsObject)
vidTempObject2 = Youtube(vidTempObject)
print(vidTempObject2.title)
if(userChoose == "search" or userChoose == "search video" or userChoose == "search videos" or userChoose == "1"):
videoSearch()
Upvotes: 0
Views: 757
Reputation: 1370
You should use YouTube
instead of Youtube
. Capitalize the t in Youtube. Like this...
from pytube import YouTube, Search
Upvotes: 1