51

We are receiving an error:

ImportError: No module named OAuth2Client

We have noticed scores of questions around this topic, many unanswered and at least one answer that describes the solution of copying over files from the Google App Engine SDK.

This approach, however, seems tedious because all the dependencies are unclear. If we copy over oauth2client then run, the next error is another module that is missing. Fix that, then another module is missing, etc., etc.

What is ironic is that we can see all the files and modules needed, listed from Google App Engine SDK right in PyCharm but they seem inaccessible to the script.

Is there no better way to pull in all the files that oauth2client needs for Python to work on App Engine?

Praxiteles
  • 5,802
  • 9
  • 47
  • 78

5 Answers5

84

I have this problem and solved by installing oauth2client with pip3:

pip3 install --upgrade oauth2client 
Community
  • 1
  • 1
Sadegh-khan
  • 2,535
  • 1
  • 20
  • 30
  • 1
    Thanks for your suggestion, I also had the import error. Solved it by putting the following in the Command Prompt pip install --upgrade oauth2client – kwant Jun 07 '18 at 13:49
  • Don't use pip's --user option or if will install to the wrong place. Especailly if you plan to deploy an app. Create and Activate a virtual env, then install it and check that oauth2client exists under (venv)/Lib/site-packages. – intotecho Oct 24 '19 at 00:01
49

As per the google-api-python documentation, try this

pip install --upgrade google-api-python-client oauth2client
Sumithran
  • 6,217
  • 4
  • 40
  • 54
  • 1
    This seems to have worked for me, running Jeremy Blythe's Motion Uploader on Raspbian 8. – CCTO Jan 05 '19 at 16:05
  • 1
    It's confusing that https://developers.google.com/api-client-library/python/guide/aaa_oauth says: "The oauth2client library is included with the Google APIs Client Library for Python." ... – olejorgenb Jan 10 '19 at 09:33
6

The answer is to "vendor" in the file(s).

We found a quick way to solve this based on this documentation https://cloud.google.com/appengine/docs/python/tools/libraries27#vendoring and this SO answer.

  1. Create a new folder called "lib" in the same folder as your app.yaml file. (You can name it something else. Just use that name below.)

  2. Create an empty file called appengine_config.py in the same folder as your app.yaml file

  3. Add two lines to that appengine_config.py file:

    from google.appengine.ext import vendor vendor.add('lib')

  4. From terminal, navigate to the directory which contains that file and execute the following command:

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

The import error will disappear and you will have all the sub-dependent modules as well.

Praxiteles
  • 5,802
  • 9
  • 47
  • 78
0

Install WHL file

pip install oauth2client-4.1.3-py2.py3-none-any.whl
Sumithran
  • 6,217
  • 4
  • 40
  • 54
-1

Run this

sudo python -m pip install oauth2client

Rahul Bhat
  • 39
  • 2
  • 11
    using `sudo pip` is really a bad idea. you are messing up your whole system package manager. please don't do this. – Dorian Jan 22 '20 at 15:59