While are you trying to import the ‘PyJWT‘ module without installing the package or If you install it in an incorrect environment. Then you will face ModuleNotFoundError: No module named ‘jwt’, this error.
In this article, we will discuss about this ModuleNotFoundError: No module named ‘jwt’ error in Python. And how to resolve the error all the possible solutions with examples.
How to ModuleNotFoundError: No module named ‘jwt’ Error Occurs?
The Python error “ModuleNotFoundError: No module named ‘jwt’” occurs for multiple reasons:
- When have you installed pip install PyJWT, there have not PyJWT package.
- You have installed the PyJWT package in a different Python version.
- If you are using the virtual environment and PyJWT module is not installed in your virtual environment.
- Declaring a variable name PyJWT.
ImportError: No module named jwt
How To Fix ModuleNotFoundError: No module named ‘jwt’ Error?
There are different ways to fix ModuleNotFoundError: No module named ‘jwt’ this error. Let us take a look at every solution.
- How To Fix ModuleNotFoundError: No module named ‘jwt’ Error?
For the solve ModuleNotFoundError: No module named ‘jwt’ Error First you have to install PyJWT module. So, opening your terminal in your project’s root directory then run this command: pip3 install PyJWT. Now, I hope your error will be solved.
Solution 1: Installing the lxml module
First of all open your terminal in your project’s root directory then run this command.
# 👇️ If you are using Python 2 (Windows)
pip install PyJWT
# 👇️ if you are using Python 3 (Windows)
pip3 install PyJWT
# 👇️ If the pip is not set as environment varibale PATH
python -m pip install PyJWT
# 👇️ If you are using Python 2 (Linux)
sudo pip install PyJWT
# 👇️ if you are using Python 3 (Linux)
sudo pip3 install PyJWT
# 👇️ In case if you have to easy_install
sudo easy_install -U PyJWT
# 👇️ On Centos
yum install PyJWT
# 👇️ On Ubuntu
sudo apt-get install PyJWT
# 👇️ If you are installing it in Anaconda
conda install -c conda-forge pyjwt
Solution 2: Installing lxml inside the virtual environment
You have to create a virtual environment if you don’t have one.
# 👇️ For python3 Create a virtual Environment
python3 -m venv venv
Now Activate the virtual environment.
# 👇️ Activate the virtual environment (windows command)
venv\Scripts\activate.bat
# 👇️ Activate the virtual environment (windows powershell)
venv\Scripts\Activate.ps1
Activate the virtual environment On Linux.
source venv/bin/activate
Now Install lxml inside the virtual environment below the command.
pip install PyJWT
Solution 3: module name is not declared name a variable name
You should check if you haven’t named a module in your project as jwt.py as it may shadow the original PyJWT module.
You shouldn’t be declaring a variable named PyJWT as that would also shadow the original module.
Solution 4: Uninstall the PyJWT
package
If the error not solved, then try to uninstall the PyJWT
package and then install it.
# 👇️ check if you have PyJWT installed
pip3 show PyJWT
# 👇️ uninstall PyJWT
pip3 uninstall PyJWT
# 👇️ install PyJWT
pip3 install PyJWT
Now, I hope your error will be solved.
Conclusion
In this article, we have discussed what causes the error and we have discussed ways to fix the error.
we hope this article has been informative. Thank you for reading. Kindly comment and let us know if you found it helpful.