8

I am using Google's python API client, and one of the lines it wants you to use is:

from apiclient import discovery

When I run this it returns the error:

ImportError: cannot import name discovery

Note: the apiclient module is installed and up to date

Thanks guys

Bennett Brown
  • 5,234
  • 1
  • 27
  • 35
Lewys Gardner
  • 81
  • 1
  • 1
  • 6
  • Possible duplicate of [ImportError: No module named apiclient.discovery](https://stackoverflow.com/questions/18267749/importerror-no-module-named-apiclient-discovery) – fredtantini Aug 03 '17 at 07:00
  • @fredtantini but then I don't know how to implement that change into my code [this](https://developers.google.com/gmail/api/quickstart/python) is the whole google python api client code i used – Lewys Gardner Aug 03 '17 at 07:05

4 Answers4

10

At some point apiclient module name was changed. If you cannot import discovery from apiclient, then try:

from googleapiclient import discovery

Hope this helps.

Michał Jabłoński
  • 1,129
  • 1
  • 13
  • 15
  • 1
    actually `apiclient` is an alias for `googleapiclient` in the latest implementations. So, this answer didn't change anything for me. Until I used the other answer: https://stackoverflow.com/a/46064844/1115187 (which is downvoted without a real reason) – maxkoryukov Aug 01 '18 at 14:47
9

You should be able to get these dependencies with this simple install:

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

See also: https://stackoverflow.com/a/23521799/1115187

maxkoryukov
  • 4,205
  • 5
  • 33
  • 54
Neeraj
  • 99
  • 3
0

Try this

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

I got the answer from this link: python install module apiclient

Marvelous Ikechi
  • 2,031
  • 2
  • 15
  • 26
0

I encountered this issue after seeing the error message "ModuleNotFoundError: No module named 'apiclient'," which prompted me to install apiclient via pip. After realizing this was probably the wrong library, I then instead installed google-api-python-client via conda, which resolved the error message.

(It looks like you were using google-api-python-client all along, but I wanted to share this in case anyone else was also trying to use the apiclient library on pip to execute google-api-python-client tasks.)

KBurchfiel
  • 635
  • 6
  • 15