[python] ImportError: No module named apiclient.discovery

I got this error in Google App Engine's Python have used Google Translate API, But I don't know how to fix,

<module>
from apiclient.discovery import build
ImportError: No module named apiclient.discovery

I'll try to set environment which indicates to Google App Engine SDK, And upload to Google Apps Engine again, always get the error,

Error: Server Error

The server encountered an error and could not complete your request. If the problem persists, please report your problem and mention this error message and the query that caused it.

Please tell me how to fix,

Thanks

UPDATE : Fixed Follow Nijjin's help, I fixed problems by adding the following folders,

apiclient, gflags, httplib2, oauth2client, uritemplate

If you still got problem, please consider below Answer of this page to get more info. ex. : Varum answer, etc ...

This question is related to python google-app-engine google-api-python-client

The answer is


This can also happen if the interpreter on your IDE is pointing to the wrong virtual environment. In VSCODE I've set it manually to the correct interpreter and my problem was solved.


I fixed the problem by reinstalling the package with:

pip install --force-reinstall google-api-python-client

I got this same error when working on a project to parse recent calendar events from Google Calendar.

Using the standard install with pip did not work for me, here is what I did to get the packages I needed.

Go directly to the source, here is a link for the google-api-python-client, but if you need a different language it should not be too different.

https://github.com/google/google-api-python-client

Click on the green "Clone or Download" button near the top left and save it as a zip file. Move the zip to your project folder and extract it there. Then cut all the files from the folder it creates back into the root of your project folder.

Yes, this does clutter your work space, but many compilers have ways to hide files.

After doing this the standard

from googleapiclient import discovery

works great.

Hope this helps.


It only worked with me when I used sudo:

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

I encountered the same issue. This worked:

>>> import pkg_resources
>>> pkg_resources.require("google-api-python-client")
[google-api-python-client 1.5.3 (c:\python27), uritemplate 0.6 (c:\python27\lib\site-packages\uritemplate-0.6-py2.7.egg), six 1.10.0 (c:\python27\lib\site-packages\six-1.10.0-py2.7.egg), oauth2client 3.0.0 (c:\python27\lib\site-packages\oauth2client-3.0.0-py2.7.egg), httplib2 0.9.2 (c:\python27\lib\site-packages\httplib2-0.9.2-py2.7.egg), simplejson 3.8.2 (c:\python27\lib\site-packages\simplejson-3.8.2-py2.7-win32.egg), six 1.10.0 (c:\python27\lib\site-packages\six-1.10.0-py2.7.egg), rsa 3.4.2 (c:\python27\lib\site-packages\rsa-3.4.2-py2.7.egg), pyasn1-modules 0.0.8 (c:\python27\lib\site-packages\pyasn1_modules-0.0.8-py2.7.egg), pyasn1 0.1.9 (c:\python27\lib\site-packages\pyasn1-0.1.9-py2.7.egg)]

>>> from apiclient.discovery import build
>>> 

apiclient is not in the list of third party library supplied by the appengine runtime: http://developers.google.com/appengine/docs/python/tools/libraries27 .

You need to copy apiclient into your project directory & you need to copy these uritemplate & httplib2 too.

Note: Any third party library that are not supplied in the documentation list must copy to your appengine project directory


Make sure you only have google-api-python-client installed. If you have apiclient installed, it will cause a collision. So, run the following:

sudo pip uninstall apiclient

There is a download for the Google API Python Client library that contains the library and all of its dependencies, named something like google-api-python-client-gae-<version>.zip in the downloads section of the project. Just unzip this into your App Engine project.


For app engine project you gotta install the lib locally by typing

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

read more here


I had the same problem because of a bug in the installation of the URITemplate module.

This solved the problem:

pip install --force-reinstall uritemplate.py

I was getting the same error, even after following Google's guide at https://developers.google.com/drive/api/v3/quickstart/python, then I realized I had to invoke like this:

python3 quickstart.py

Instead of:

python quickstart.py <-- WRONG

(Note the "3")

Worked flawlessly.

I'm using Ubuntu 18.04.4 LTS.


The same error can be seen if you are creating a Python module and your executing the script after installing it via pip or pipx command. In this case ensure you have declared what the project minimally needs to run correctly into install_requires section of your setup.py file, so in this case:

install_requires=[
    "google-api-python-client>=1.12.3",
    "google-auth-httplib2>=0.0.4",
    "google-auth-oauthlib>=0.4.1"
]

for python3 this worked for me:

sudo pip3 install --upgrade google-api-python-client

If none of the above solutions work for you, consider if you might have installed python through Anaconda. If this is the case then installing the google API library with conda might fix it.

Run:

python --version

If you get something like

Python 3.6.4 :: Anaconda, Inc.

Then try:

conda install google-api-python-client

As bgoodr has pointed out in a comment you might need to specify the channel (think repository) to get the google API library. At the time of writing this means running the command:

conda install -c conda-forge google-api-python-client

See more at https://anaconda.org/conda-forge/google-api-python-client


apiclient was the original name of the library.
At some point, it was switched over to be googleapiclient.

If your code is running on Google App Engine, both should work.

If you are running the application yourself, with the google-api-python-client installed, both should work as well.

Although, if we take a look at the source code of the apiclient package's __init__.py module, we can see that the apiclient module was simply kept around for backwards-compatibility.

Retain apiclient as an alias for googleapiclient.

So, you really should be using googleapiclient in your code, since the apiclient alias was just maintained as to not break legacy code.

# bad
from apiclient.discovery import build

# good
from googleapiclient.discovery import build

use this

pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

"google-api-python-client" requires:

pip install uritemplate.py

to fix problem on GAE Development Server:

from googleapiclient.discovery import build

ImportError: No module named googleapiclient.discovery

Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to google-app-engine

Problems with installation of Google App Engine SDK for php in OS X Get Public URL for File - Google Cloud Storage - App Engine (Python) Visual Studio Code pylint: Unable to import 'protorpc' Get root password for Google Cloud Engine VM Spring Boot - Cannot determine embedded database driver class for database type NONE What is the difference between Google App Engine and Google Compute Engine? Cross-Origin Request Blocked Class JavaLaunchHelper is implemented in both. One of the two will be used. Which one is undefined ImportError: No module named apiclient.discovery java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

Examples related to google-api-python-client

ImportError: No module named apiclient.discovery How do I access (read, write) Google Sheets spreadsheets with Python?