ModuleNotFoundError: No module named 'jwt'
Third-person routing: this skill fixes ModuleNotFoundError: No module named 'jwt' after installing the wrong package or installing PyJWT into the wrong interpreter. It covers the pip-name vs import-name mismatch (PyJWT provides jwt). Use when import jwt fails. Not for PyJWT API changes, decode algorithm errors, or python-jose confusion.
ModuleNotFoundError: No module named 'jwt'
TL;DR: the import is jwt but the pip package is PyJWT. Run python -m pip install PyJWT. If it is already installed, your pip and python are different interpreters; python -m pip fixes that too.
ModuleNotFoundError: No module named 'jwt'The fix
- Install with the same interpreter that runs your code:
python -m pip install PyJWT
python -c "import jwt; print(jwt.__version__)"Success check: prints a version like 2.8.0.
- If it says already satisfied but the import still fails, you have two Pythons:
python -c "import sys; print(sys.executable)"
python -m pip show PyJWT | grep LocationThe Location must sit under the same prefix as sys.executable. If not, reinstall into the right one with python -m pip.
- If you need RSA/ECDSA support, install the crypto extra:
python -m pip install "PyJWT[crypto]".
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=pyjwt+No+module+named+jwt'
When this applies
import jwtfails right after a fresh clone or in a new venv/CI container.- A tutorial told you to
pip install jwt, which installs an unrelated dead package.
When it does NOT apply
ImportError: cannot import name 'PyJWT' from 'jwt': you have a shadowing file or ancient version; different fix.jwt.exceptions.ExpiredSignatureErroror decode errors: the import works, your token or call is wrong.- python-jose users: that package imports as
jose, notjwt.
Tool and version compatibility
PyJWT 2.x, Python 3.7+. PyJWT 1.x is ancient; upgrade.
Why it happens
PyPI name and import name differ: pip install PyJWT gives you import jwt. There is also a squatter package literally named jwt that does nothing useful. Installing the wrong one, or installing into a different interpreter than the one running the code, produces exactly this error.
Edge cases
- A file named
jwt.pyin your project shadows the package; rename it. - If both
jwtandPyJWTshow in pip list, uninstalljwt. - In Docker, make sure the pip install happens in the same layer/stage that runs the app.
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.