Modulenotfounderror: no module named rest_framework ( Solved )

Modulenotfounderror_ no module named rest_framework ( Solved )

You must have used Django Framework for the machine learning dashboard.The python module djangorestframework allows you to build RESTful web applications. But if you are getting the error modulenotfounderror: no module named rest_framework then this post is for you. You will learn why you are getting this error and how you can solve it.

What is ModuleNotFoundError ?

Most of case the programmer or developer get this ModuleNotFoundError when they try to import a module and the python interpreter unable to find it. For example, if you try to import the module “X” and if it is not installed in your system then you will get the error “ModuleNotFoundError: no module named “X”.

Why does the modulenotfounderror: no module named rest_framework occur?

The main or root cause for this error is that the python interpreter is unable to find the djangorestframework module in your system. You will get the error when you import this rest_framework.

import rest_framework

Output

No module named rest framework
No module named rest framework

 

Solve the no module named rest_framework Error

Solution 1: 

The solution to this no module named error is very simple. You have to just install the djangorestframework using the pip command. You have to first verify the version of python. If your python version is 3. xx then use the pip3 command and if it is 2. xx then use the pip command.

For python 3.xx

pip3 install djangorestframework

For python 2.xx

pip install djangorestframework

Now you will not get the error when you import this module.

For conda

conda install djangorestframework

Solution 2: 

But if you are still getting this error then you have to set the python path. Open your terminal and type the below command.

export PYTHONPATH=~/rest_framework

Solution 3:

If you’re still getting the “ModuleNotFoundError” error then it’s possible that the djangorestframework module is installed. But Django is unable to find it.  For this case add the module to your Django settings:

INSTALLED_APPS = [ ... 'rest_framework', ]

After making the changes you have to restart your Django application. After restarting, you may not get the “ModuleNotFoundError”.

Conclusion

Django Rest Framework is a plugin for the Django that allows you to build web APIs. If you are getting the error modulenotfounderror: no module named rest_framework then the above solution will solve it.

I hope you have liked this tutorial. If your problem has not still solved then you can contact us for more help.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner