No module named googleapiclient.discovery

风格不统一 提交于 2020-07-08 11:05:12

问题


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

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

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

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

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:\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.

What am I doing wrong?

Thanks


回答1:


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.


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

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

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


来源:https://stackoverflow.com/questions/51571392/no-module-named-googleapiclient-discovery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!