In this article, we will provide solutions on “how to solve the Modulenotfounderror: no module named rest_framework” error in Windows, Anaconda, and Jupyter Notebook.
The “error no module named rest_framework” appears if we forgot to install the “djangorestframework” package or the system cannot find it.
So, if you import the rest_framework you will get an error.
Also read: Modulenotfounderror: no module named conda [SOLVED]
What is ModuleNotFoundError?
Most of all the developers and programmers get encountered this ModuleNotFoundError when they are trying to import a package. The python interpreter will not able to find it.
Solutions for no module named rest_framework
Time needed: 3 minutes.
Here are the solutions to solve the no module named rest_framework
- Solution 1: Install in Python2, Python3, Jupyter Notebook and Conda
The solution to this error problem is very simple. You need to install the djangorestframework with the use of the PIP command.
First, you need to justify the python version. After you justify the python version, for example your python version is 3 you will use the pip3 command and if it is version 2 use the pip command only.
Installation for Python 2:
“pip install djangorestframework“
Installation for Python 3:
“pip3 install djangorestframework“
Installation for Conda:
“conda install djangorestframework“
Installation for Jupyter Notebook:
“!pip install djangorestframework“
- Solution 2: Install PIP in Path Environment Variable
When you don’t have installed pip in your PATH environment variable. This is the following command to install:
“python -m pip install djangorestframework“
- Solution 3: Export Rest framework
When the error will continue then you have to set the python path. Open your terminal in project folder directory and type the following command.
- Solution 4: Add Django Settings
When the “ModuleNotFoundError” error will continue then it’s possible that the djangorestframework package is installed. However, the Django can’t able to find it. For this situation add the package to your Django settings:
“INSTALLED_APPS = [ … ‘rest_framework’, ]”
After the changes, you have to restart your Django app. After restarting your computer, the “ModuleNotFoundError” should already be solved.
To conclude, the Django Rest Framework is a library package for the Django that allows you to create web APIs.
When you encounter the error modulenotfounderror: no module named rest_framework then the above solutions should be solved and fixed for it.