gpt4 book ai didi

python - 没有名为 googleapiclient.discovery 的模块

转载 作者:太空宇宙 更新时间:2023-11-03 12:00:09 28 4
gpt4 key购买 nike

我一直在寻求实现我在网上找到的示例 Python 脚本,以允许我根据找到的 GitHub 链接与 YouTube API 进行交互 here

我遇到的问题是开头的导入语句:

import argparse

from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

在线文档需要以下命令来安装 googleapiclient 库:

pip install --upgrade google-api-python-client

但是,安装后我仍然收到无法找到 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.

我做错了什么?

谢谢

最佳答案

如果您正在运行 Python3 (python --version),也许您应该改为运行:

 pip3 install google-api-python-client

解决此问题的另一种快速方法是将包安装在与您的代码相同的文件夹中:

 pip install google-api-python-client -t ./

这并不理想,但肯定会奏效。


或者如果您希望将外部库移动到 lib/ 文件夹:

pip install google-api-python-client -t ./lib

在后一种情况下,您还需要在 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

关于python - 没有名为 googleapiclient.discovery 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51571392/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com