Django Rest Framework -- no module named rest_framework

217,496

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!

  1. Exit from your virtual environment.

  2. 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.

Share:
217,496

Related videos on Youtube

tryingtolearn
Author by

tryingtolearn

Updated on April 09, 2022

Comments

  • tryingtolearn
    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
      Burger King over 8 years
      Have you installed in settings.py?
    • tryingtolearn
      tryingtolearn over 8 years
      @BurgerKing I added rest_framework to my installed apps. Is that what you meant?
    • Vingtoft
      Vingtoft over 8 years
      Are you using a virtuel environment?
    • Burger King
      Burger King over 8 years
      I just try to guess reason. May you give your error message?
    • tryingtolearn
      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
      tryingtolearn over 8 years
      @BurgerKing "ImportError: No module named 'rest_framework'" is the error.
  • tryingtolearn
    tryingtolearn over 8 years
    I see what you mean. I'm getting an error: "apt-get: command not found" when I try to run your command though.
  • Drew S
    Drew S over 6 years
    Glad I scrolled down past trying to reinstall DRF. This solved it for me.
  • ulmas
    ulmas over 5 years
    Not everyone uses the same editor, and not all editors provide the same feature to import modules through the light bulb.
  • rammanoj
    rammanoj over 5 years
    I am not sure why but I am still facing the same issue
  • snowblindzz
    snowblindzz over 4 years
    This solves my problem. In my case I have done codepip install djangorestframeworkcode in the windows powershell
  • athenatechie
    athenatechie over 4 years
    I agree such a sneaky thing.
  • nzajt
    nzajt over 4 years
    Nice work on your first answer, but make sure you format code correctly. stackoverflow.com/editing-help.
  • Punnerud
    Punnerud over 3 years
    if pip3 does not work, try: python3 -m pip install djangorestframework
  • Srinivas Batchu
    Srinivas Batchu over 3 years
    Thanks for mentioning typo. I am using rest_framwork instead of rest_framework. Missing e in framework. :)
  • Mr How
    Mr How about 3 years
    why is it need put first app tell me please?
  • Rodrigo Vaamonde
    Rodrigo Vaamonde about 3 years
    And 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
    alelom almost 3 years
    Instead 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
    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
    alelom almost 3 years
    Thank 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
    Digin Dominic almost 3 years
    /usr/bin/env /bin/python3 manage.py makemigrations fixed my problem