I got an error,ModuleNotFoundError: No module named 'rest_framework' when I run command python manage.py runserver
.
Traceback says
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x108193ae8>
Traceback (most recent call last):
File "/Users/xxx/anaconda/envs/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/xxx/anaconda/envs/env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/Users/xxx/anaconda/envs/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Users/xxx/anaconda/envs/env/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/xxx/anaconda/envs/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/xxx/anaconda/envs/env/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/xxx/anaconda/envs/env/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/xxx/anaconda/envs/env/lib/python3.6/site-packages/django/apps/config.py", line 116, in create
mod = import_module(mod_path)
File "/Users/xxx/anaconda/envs/env/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'rest_framework'
I already run command pip3 install djangorestframework
,when I run this command again, Requirement already satisfied: djangorestframework in /usr/local/lib/python3.6/site-packages shows in terminal.Python version is 3.6.2.What is wrong in my code?How should I fix this?I use Anaconda virtual environment.
It looks as if pip3 install
has installed the package into /usr/local/lib/python3.6/site-packages
, instead of your environment /Users/xxx/anaconda/envs/env/lib/python3.6/site-packages
.
If you use python -m pip
, then the package will be installed in the same version of python that you use when you run python manage.py runserver
. This is the suggested command in the Python docs.
python -m pip install djangorestframework
Did you add rest_framework in your setup?
INSTALLED_APPS = [
'rest_framework',
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
May be this post will help you. Have a look.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With