ModuleNotFoundError: No module named 'oauth2client'
Fixes legacy Google API code that still imports the retired oauth2client library. Use when old samples or dependencies import oauth2client. Not for modern google-auth code.
TL;DR: oauth2client is dead upstream. Migrate the import to google-auth: service account code becomes google.oauth2.serviceaccount, and user OAuth becomes googleauth_oauthlib.flow. Pinning oauth2client is a stopgap at best.
ModuleNotFoundError: No module named 'oauth2client'Fix it
- Find the imports: grep -rn "oauth2client" your code. Expected: a short list.
- Service accounts: replace
from oauth2client.service_account import ServiceAccountCredentialswithfrom google.oauth2 import service_account, and ServiceAccountCredentials.fromjsonkeyfilename(...) with serviceaccount.Credentials.fromserviceaccount_file(...). Expected: no oauth2client references left. - User OAuth: replace oauth2client.client.flowfromclientsecrets with googleauthoauthlib.flow.InstalledAppFlow.fromclientsecrets_file. Expected: the flow completes.
- Install the new libs: pip install google-auth google-auth-oauthlib. Expected: imports succeed.
When this applies
- Your code or a dependency imports oauth2client.
When it doesn't
- Modern code already uses google-auth: this error means a stale dependency; upgrade it.
- You just need it running today: pip install oauth2client works but inherits unmaintained code.
Compatibility
- google-auth >= 1.0; Python 3.8+.
Why it happens
Google deprecated oauth2client in 2017 and archived it. New environments never have it, so legacy samples fail on import while modern ones work.
Edge cases
- Some old google-api-python-client versions still import oauth2client internally; upgrade google-api-python-client past 1.7.
- The credential JSON formats are compatible, so key files do not need regeneration.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.