没有名为 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 的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)