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条回答
祖国的老花朵
2楼-- · 2020-05-19 04:18

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

查看更多
\"骚年 ilove
3楼-- · 2020-05-19 04:18

If you are working with PyCharm, I found that restarting the program and closing all prompts after adding 'rest_framework' to my INSTALLED_APPS worked for me.

查看更多
你好瞎i
4楼-- · 2020-05-19 04:18

if you used pipenv:

if you installed rest_framework thru the new pipenv, you need to run it thru the virtual environment:

1.pipenv shell

2.(env) now, run your command(for example python manage.py runserver)

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2020-05-19 04:19

First installing the framework globally on the system solved my problem.

machine@debian:/$ sudo pip install djangorestframework
or;
root@debian:/# pip install djangorestframework
查看更多
疯言疯语
6楼-- · 2020-05-19 04:21

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.

查看更多
【Aperson】
7楼-- · 2020-05-19 04:21

In my case, my problem was different. I was creating in my bash_profile an alias like:

alias python=/usr/local/bin/python3

And even if I activate my environment, when I ran the command, the python interpreter accessed was from the system and not from my environment.

I just removed the alias from bash_profile and it worked fine.

查看更多
登录 后发表回答