没有名为 googleapiclient.discovery 的模块

No module named googleapiclient.discovery(没有名为 googleapiclient.discovery 的模块)

本文介绍了没有名为 googleapiclient.discovery 的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been looking to implement the example Python scripts I have found online to allow me to interact with the YouTube API as per the GitHub link found here

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

The problem I am having is with the import statement at the start:

import argparse

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

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

The online documentation requires the following command to install the googleapiclient library:

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

但是,一旦安装,我仍然收到无法找到 googleapiclient.discovery 的错误.我尝试通过 pip 重新安装,生成以下命令行输出,表明一切正常:

However, once installed I am still receiving an error that googleapiclient.discovery cannot be found. I have tried reinstalling via pip, with the following command line output generated, suggesting all is well:

Requirement already up-to-date: google-api-python-client in g:python27libsite-packages (1.7.4)
Requirement not upgraded as not directly required: httplib2<1dev,>=0.9.2 in g:python27libsite-packages (from google-api-python-client) (0.9.2)
Requirement not upgraded as not directly required: google-auth>=1.4.1 in g:python27libsite-packages (from google-api-python-client) (1.5.0)
Requirement not upgraded as not directly required: google-auth-httplib2>=0.0.3 in g:python27libsite-packages (from google-api-python-client) (0.0.3)
Requirement not upgraded as not directly required: six<2dev,>=1.6.1 in g:python27libsite-packages (from google-api-python-client) (1.10.0)
Requirement not upgraded as not directly required: uritemplate<4dev,>=3.0.0 in g:python27libsite-packages (from google-api-python-client) (3.0.0)
Requirement not upgraded as not directly required: rsa>=3.1.4 in g:python27libsite-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:python27libsite-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:python27libsite-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:python27libsite-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),也许你应该运行这个:

In case you are running Python3 (python --version), perhaps you should run this instead:

 pip3 install google-api-python-client

<小时>

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


Another quick way to counter this problem could be to install the package in the same folder as your code:

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

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

That's not ideal but it will definitely work.

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

Or if you prefer to move external libraries to a lib/ folder:

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

在最后一种情况下,您还需要在 Python 代码的开头使用它:

in that last case you will also need this at the beginning of your Python code:

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

这篇关于没有名为 googleapiclient.discovery 的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:没有名为 googleapiclient.discovery 的模块

基础教程推荐