GSpread ImportError: no module named oauth2client.service_account

Ok, I'm following the Become A Technical Marketer course, and I'm trying to learn how to manage Google Spreadsheets using GSpread. I accompanied the documentation at http://gspread.readthedocs.io/en/latest/oauth2.html . I followed the steps in the second URL above and ran the document with the following code:

import gspread from oauth2client.service_account import ServiceAccountCredentials scope = ['https://spreadsheets.google.com/feeds'] credentials = ServiceAccountCredentials.from_json_keyfile_name('DFS Google Sheets Data Imports-7205de852ff7.json', scope) gc = gspread.authorize(credentials) wks = gc.open("Authority Scraper").sheet1 wks.update_cell(1,2,"Hello World!") 

From this I get an error in my terminal: from oauth2client.service_account import ServiceAccountCredentials ImportError: there is no module named oauth2client.service_account

terminal error listing

Someone please help me. Answers with another module No named oath2client.service_account do not work for me. Thanks!

+5
source share
4 answers

According to this discussion ,

This is because OS X El Capitan comes with six installed 1.4.1, and when he tries to uninstall it, he does not have permission to do this, since System Integrity Protection does not even allow root to change these directories.

Among the several workarounds mentioned in the answers, it might be worth trying pip install --ignore-installed six avoid trying to remove the six system package.

+3
source

Running this command worked for me - sudo pip install --upgrade oauth2client

Got it from the oauth2client github repo library

+1
source

You can fix the error by checking if there are multiple directories in your library.

 C:\Python27\Lib\site-packages\oauth2client C:\Program Files (x86)\Google\Google_Appengine\lib\google-api-python-client\oauth2client 

you just need to delete one of the folders or change the library path in the compiler.

Here is the link to the video that I made on the topic:

How to fix: "There is no module named service_account" - Python

+1
source

So I just ran into this problem, and it turned out to be a problem for me. Of course, I know this is a little far-fetched (as each development environment is different), but writing it down here if it helps someone else.

TL; DR make sure that something does not reset your $PYTHONPATH .

Recall that when you do the β€œimport” in python, python checks your sys.path for packages. This list has a priority order (i.e. if a package is found in an earlier path in the list, then this package will be used).

In my case, it looks like my $PYTHONPATH was changed when I made some appengine applications some time ago. As it turned out, my appengine had its own oauth2client lib, which is pretty old.

As a result, when python tried from oauth2client.service_account , it grabbed oauth2client in appengine, not oauth2client , which I expected it to oauth2client (the result of changing $PYTHONPATH ).

You can check if this happens to you by printing sys.path before calling the import:

 import sys print sys.path from oauth2client.service_account import ServiceAccountCredentials 

In my case, I could clearly see a bunch of application paths that took precedence. This led me to check my ~/.bash_profile , where wala I found this line:

 export PYTHONPATH=$PYTHONPATH::$LOCAL_APPENGINE_HOME/lib/:$LOCAL_APPENGINE_HOME/lib/yaml/:$LOCAL_APPENGINE_HOME:$LOCAL_APPENGINE_HOME/lib/webapp2-2.5.2/` 

Commented on this, started a new shell, and everything worked dandy.

0
source

All Articles