gdo*_*371 6 python pip youtube-api kodi
我一直在寻找实现我在网上找到的示例 Python 脚本,以允许我按照此处的 GitHub 链接与 YouTube API 进行交互
我遇到的问题是开头的导入语句:
import argparse
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
Run Code Online (Sandbox Code Playgroud)
在线文档需要以下命令来安装googleapiclient库:
pip install --upgrade google-api-python-client
Run Code Online (Sandbox Code Playgroud)
但是,一旦安装,我仍然收到一个googleapiclient.discovery无法找到的错误。我尝试通过 pip 重新安装,生成了以下命令行输出,表明一切正常:
Requirement already up-to-date: google-api-python-client in g:\python27\lib\site-packages (1.7.4)
Requirement not upgraded as not directly required: httplib2<1dev,>=0.9.2 in g:\python27\lib\site-packages (from google-api-python-client) (0.9.2)
Requirement not upgraded as not directly required: google-auth>=1.4.1 in g:\python27\lib\site-packages (from google-api-python-client) (1.5.0)
Requirement not upgraded as not directly required: google-auth-httplib2>=0.0.3 in g:\python27\lib\site-packages (from google-api-python-client) (0.0.3)
Requirement not upgraded as not directly required: six<2dev,>=1.6.1 in g:\python27\lib\site-packages (from google-api-python-client) (1.10.0)
Requirement not upgraded as not directly required: uritemplate<4dev,>=3.0.0 in g:\python27\lib\site-packages (from google-api-python-client) (3.0.0)
Requirement not upgraded as not directly required: rsa>=3.1.4 in g:\python27\lib\site-packages (from google-auth>=1.4.1->google-api-python-client) (3.4.2)
Requirement not upgraded as not directly required: cachetools>=2.0.0 in g:\python27\lib\site-packages (from google-auth>=1.4.1->google-api-python-client) (2.1.0)
Requirement not upgraded as not directly required: pyasn1-modules>=0.2.1 in g:\python27\lib\site-packages (from google-auth>=1.4.1->google-api-python-client) (0.2.2)
Requirement not upgraded as not directly required: pyasn1>=0.1.3 in g:\python27\lib\site-packages (from rsa>=3.1.4->google-auth>=1.4.1->google-api-python-client) (0.1.9)
pyasn1-modules 0.2.2 has requirement pyasn1<0.5.0,>=0.4.1, but you'll have pyasn1 0.1.9 which is incompatible.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
谢谢
如果您正在运行 Python3 ( python --version),也许您应该运行它:
pip3 install google-api-python-client
Run Code Online (Sandbox Code Playgroud)
解决此问题的另一种快速方法是将软件包安装在与代码相同的文件夹中:
pip install google-api-python-client -t ./
Run Code Online (Sandbox Code Playgroud)
这并不理想,但肯定会奏效。
或者,如果您更喜欢将外部库移动到lib/文件夹:
pip install google-api-python-client -t ./lib
Run Code Online (Sandbox Code Playgroud)
在最后一种情况下,您还需要在 Python 代码的开头使用它:
import os
import sys
file_path = os.path.dirname(__file__)
module_path = os.path.join(file_path, "lib")
sys.path.append(module_path)
from googleapiclient.discovery import build
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13001 次 |
| 最近记录: |