ModuleNotFoundError: No module named 'jose'
Explains why `from jose import jwt` throws ModuleNotFoundError: No module named 'jose' and how to fix it with `pip install python-jose`. Use when the jose import fails on a fresh environment. Not for the Python-2-syntax variant of jose problems.
ModuleNotFoundError: No module named 'jose'
TL;DR: the distribution is called python-jose, not jose. Run pip install python-jose (and uninstall the unrelated jose package if you installed it by mistake).
ModuleNotFoundError: No module named 'jose'The fix
pip uninstall -y jose
pip install "python-jose[cryptography]"Verify:
python -c "from jose import jwt; print(jwt.encode({'a': 1}, 'secret', algorithm='HS256'))"Expected output: a three-part token string.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=python-jose+No+module+named+jose'
When this applies
from jose import jwtfails on a fresh virtualenv or container.- You ran
pip install joseand it did not help. - Following FastAPI or Flask JWT tutorials that import jose.
When it does NOT apply
SyntaxError: Missing parentheses in call to 'print', which means the wrongjosepackage is actually installed.No module named 'jwt', which is the PyJWT naming trap, a different package.
Why this happens
Same trap as PyJWT and argon2: the import name and the distribution name differ, and PyPI has an unrelated project squatting on the obvious name. pip installs what you asked for, which was the wrong project. The [cryptography] extra pulls in the backend needed for RS256/ES256 algorithms.
Compatibility
python-jose 3.x. The unrelated jose distribution is Python 2 only and must not be installed.
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.