Django Rest Framework — no module named rest_frame

2020-05-19 03:40发布

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?

18条回答
Juvenile、少年°
2楼-- · 2020-05-19 04:03

When using a virtual environment like virtualenvwithout having django-rest-framework installed globally you might as well have the error. The solution would be:

  • activate the environment first with {{your environment name}}/bin/activate for Linux or {{your environment name}}/Scripts/activate for Windows

  • and then run the command again.

查看更多
冷血范
3楼-- · 2020-05-19 04:04

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

查看更多
Emotional °昔
4楼-- · 2020-05-19 04:04

try this if you are using JWT pip install djangorestframework-jwt

查看更多
在下西门庆
5楼-- · 2020-05-19 04:04

I know there is an accepted answer for this question and many other answers also but I just wanted to add an another case which happened with me was Updating the django and django rest framework to the latest versions to make them work properly without any error.

So all you have to do is just uninstall both django and django rest framework using:

pip uninstall django pip uninstall djangorestframework

and then install it again using:

pip install django pip install djangorestframework

查看更多
看我几分像从前
6楼-- · 2020-05-19 04:05

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',
]
查看更多
\"骚年 ilove
7楼-- · 2020-05-19 04:05

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.

查看更多
登录 后发表回答