没有命名的模块googleapiclient.discovery

2024-05-16 22:31:12 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我遇到的问题是开始时的import语句:

import argparse

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

联机文档需要以下命令来安装googleapiclient库:

^{pr2}$

{cd2>仍然无法安装^接收错误。我尝试通过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.

我做错什么了?在

谢谢


Tags: infromclientapilibpackagesasgoogle
1条回答
网友
1楼 · 发布于 2024-05-16 22:31:12

如果您运行的是Python3(python version),也许您应该运行以下命令:

 pip3 install google-api-python-client

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

^{pr2}$

这不太理想,但肯定会奏效的。在


或者,如果您希望将外部库移动到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

相关问题 更多 >