ModuleNotFoundError: No module named 'oauth2_provider'
Explains why `import oauth2_provider` throws ModuleNotFoundError and how to fix it with `pip install django-oauth-toolkit`. Use when the import fails on a fresh environment. Not for OAuth2 provider configuration errors.
ModuleNotFoundError: No module named 'oauth2_provider'
TL;DR: the distribution is called django-oauth-toolkit. Run pip install django-oauth-toolkit and the import works.
ModuleNotFoundError: No module named 'oauth2_provider'The fix
pip install django-oauth-toolkitThen add oauth2_provider to INSTALLED_APPS and include its URLs per the README.
Verify:
python -c "import oauth2_provider; print('ok')"Expected output: ok.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=django-oauth-toolkit+No+module+named+oauth2_provider'
When this applies
- Turning a Django app into an OAuth2 provider (issuing tokens to third parties).
- Fresh virtualenvs, Docker builds, or CI runners.
- Confusing this with oauth client libraries like authlib or requests-oauthlib.
When it does NOT apply
- OAuth2 client-side code, where authlib or requests-oauthlib is the right package.
- Token or scope configuration errors after the import works.
Why this happens
The distribution name describes the Django toolkit; the module name describes the OAuth2 provider app inside it. pip needs the long name, Python imports the short one. This is the same split as djangorestframework-simplejwt and django-allauth.
Compatibility
django-oauth-toolkit 2.x/3.x with Django 4.x/5.x. Version 2.0+ dropped older Django; check the changelog when upgrading.