Django Rest Framework -- no module named rest_framework
Solution 1
You need to install django rest framework using pip3 (pip for python 3):
pip3 install djangorestframework
Instructions on how to install pip3 can be found here
Solution 2
if you forget ,
,this will happen,it's weird
wrong example: need a ,
INSTALLED_APPS = [
'rest_framework'
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Solution 3
Also, check for the possibility of a tiny typo:
It's rest_framework
with an underscore (_
) in between!
Took me a while to figure out that I was using a dash instead... 😅
Solution 4
If you're using some sort of virtual environment do this!
Exit from your virtual environment.
Activate your virtual environment.
After you've done this you can try running your command again and this time it probably won't have any ImportErrors.
Solution 5
Maybe you install DRF is for python2, not for python3.
You can use python console
to check your module:
import rest_framework
Actually you use pip
to install module, it will install python2 module.
You should install the pip for python3:
sudo apt-get install python3-setuptools
sudo easy_install3 pip
So, you can install python3 module.
Related videos on Youtube
tryingtolearn
Updated on April 09, 2022Comments
-
tryingtolearn about 2 years
I've installed django rest framework using
pip install djangorestframework
yet I still get this error when I run "python3 manage.py sycndb":ImportError: No module named 'rest_framework'
I'm using python3, is this my issue?
-
Burger King over 8 yearsHave you installed in
settings.py
? -
tryingtolearn over 8 years@BurgerKing I added rest_framework to my installed apps. Is that what you meant?
-
Vingtoft over 8 yearsAre you using a virtuel environment?
-
Burger King over 8 yearsI just try to guess reason. May you give your error message?
-
tryingtolearn over 8 years@Vingtoft I'm not. I was following this tutorial: youtube.com/watch?v=VZ8NIoLN-yQ at the 5 minute mark.
-
tryingtolearn over 8 years@BurgerKing "ImportError: No module named 'rest_framework'" is the error.
-
-
tryingtolearn over 8 yearsI see what you mean. I'm getting an error: "apt-get: command not found" when I try to run your command though.
-
Drew S over 6 yearsGlad I scrolled down past trying to reinstall DRF. This solved it for me.
-
ulmas over 5 yearsNot everyone uses the same editor, and not all editors provide the same feature to import modules through the light bulb.
-
rammanoj over 5 yearsI am not sure why but I am still facing the same issue
-
snowblindzz over 4 yearsThis solves my problem. In my case I have done
code
pip install djangorestframeworkcode
in the windows powershell -
athenatechie over 4 yearsI agree such a sneaky thing.
-
nzajt over 4 yearsNice work on your first answer, but make sure you format code correctly. stackoverflow.com/editing-help.
-
Punnerud over 3 yearsif pip3 does not work, try: python3 -m pip install djangorestframework
-
Srinivas Batchu over 3 yearsThanks for mentioning typo. I am using
rest_framwork
instead ofrest_framework
. Missinge
inframework
. :) -
Mr How about 3 yearswhy is it need put first app tell me please?
-
Rodrigo Vaamonde about 3 yearsAnd here I am trying to find what sort of dark arts I needed to perform to make this work, and all it was, was a damn typo! Thank you!
-
alelom almost 3 yearsInstead of answers that point out the obvious ("install django, duh") check that you don't have a missing comma in the INSTALLED_APPS list, because that weirdly triggers this ImportError. Kudos to this answer.
-
Vingtoft almost 3 years@alexlomba87, this error also appears if you use python3 but have installed django using pip for python 2.7, which is why this answer does not point out the obvious for many developers.
-
alelom almost 3 yearsThank you for adding that, I'd advice to update the answer to add that info, which is not explicit. Pip3 may be the default for many.
-
Digin Dominic almost 3 years/usr/bin/env /bin/python3 manage.py makemigrations fixed my problem