无法导入名称 "Youtube"?
cannot import name "Youtube"?
我需要帮助,我在 python 代码中遇到了问题。
我已经从 cmd 安装了 pytube 模块
pip install pytube
并“成功安装”,还安装了 pip install pytube3
,vs 代码在调试中没有发现任何错误,但是当我尝试 运行 我的代码时,我得到了这个错误:
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)
我也试过 pip install pytube3 --upgrade
和 pip install pytube --upgrade
并得到
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)
这是代码:
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()
您应该使用 YouTube
而不是 Youtube
。将 Youtube 中的 t 大写。像这样...
from pytube import YouTube, Search
我需要帮助,我在 python 代码中遇到了问题。
我已经从 cmd 安装了 pytube 模块
pip install pytube
并“成功安装”,还安装了 pip install pytube3
,vs 代码在调试中没有发现任何错误,但是当我尝试 运行 我的代码时,我得到了这个错误:
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)
我也试过 pip install pytube3 --upgrade
和 pip install pytube --upgrade
并得到
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)
这是代码:
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()
您应该使用 YouTube
而不是 Youtube
。将 Youtube 中的 t 大写。像这样...
from pytube import YouTube, Search