ModuleNotFoundError: No module named 'requests_oauthlib'
Explains why `from requests_oauthlib import OAuth2Session` throws ModuleNotFoundError and how to fix it with `pip install requests-oauthlib`. Use when the import fails on a fresh environment. Not for OAuth flow errors.
ModuleNotFoundError: No module named 'requests_oauthlib'
TL;DR: the distribution uses a dash: pip install requests-oauthlib. The underscore version is the module name, not the pip name.
ModuleNotFoundError: No module named 'requests_oauthlib'The fix
pip install requests-oauthlibVerify:
python -c "from requests_oauthlib import OAuth2Session; print('ok')"Expected output: ok.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=requests-oauthlib+No+module+named'
When this applies
- OAuth1/OAuth2 client code built on requests.
- You ran
pip install requests_oauthlib(underscore) and it failed. - Fresh virtualenvs, containers, or CI runners.
When it does NOT apply
- OAuth flow errors (redirect URIs, token exchange) after the import works.
No module named 'oauthlib', which is the underlying library missing.
Why this happens
PyPI normalizes dashes and underscores in most lookups, but the canonical project name here uses a dash and some install paths are picky. The module keeps the underscore because dashes are not valid in Python identifiers. When in doubt, copy the install command from the PyPI page.
Compatibility
requests-oauthlib 1.3+/2.x with requests 2.x and oauthlib 3.x, installed automatically.