[Fixed]-Configure Django-rest

24👍

is rest_framework actually installed and on your PYTHONPATH?

That looks like a basic import error.

Suggest you:

Double check everything’s installed correctly, by running “manage.py shell” and trying both “import rest_framework” and “from rest_framework import authtoken”.

I would install with pip not easy if you can, easy has given me many issues like this before.

sudo pip install djangorestframework

4👍

You’re installing the wrong package. The package is named djangorestframework, not django-rest.

0👍

another completely different cause of this “Error:-No module named rest_framework

my virtual environment folder was not subfolder of my project (e.g. if you don’t have an ‘env’ subfolder within your project, but you have your virtual env in another folder structure)

for example: I used to make all my virtual environments in a separate folder path, then I had a bat file to activate my virtual environment within each project. I had a ‘master folder’ for all my virtual env subfolders — which made all of them ‘findable’ within the same environment PATH — this was working for me on many prior projects, not sure if it’s a python3 vs python2 issue or a DRF issue — but — I just upgraded from python 2.7 to 3.6 and this was my experience — hopefully this helps someone else.

(1) navigate to your project folder (e.g. D:\projects\myproject)

(2) make your virtual env folder within the project folder
virtualenv env

(3) activate your virtualenv
env\Scripts\activate

OLD FOLDER STRUCTURE: (doesn’t work)

D:\projects\myproject\env <— python code here

D:\python\virtualenvs\my_project <– virtual env here

NEW FOLDER STRUCTURE (this works)

D:\projects\myproject <— python code here

D:\projects\myproject\env <– virtual env here

Leave a comment