Forums

Django rest framework import

I got my rest_framework installed but when I add 'rest_framework' to my INSTALLED_APPS I got the next error in my error.log.

2018-04-25 19:11:43,793: Error running WSGI application
2018-04-25 19:11:43,794: ModuleNotFoundError: No module named 'rest_framework'
2018-04-25 19:11:43,794:   File "/var/www/kambo_pythonanywhere_com_wsgi.py", line 25, in <module>
2018-04-25 19:11:43,794:     application = get_wsgi_application()
2018-04-25 19:11:43,794: 
2018-04-25 19:11:43,794:   File "/usr/local/lib/python3.6/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2018-04-25 19:11:43,795:     django.setup(set_prefix=False)
2018-04-25 19:11:43,795: 
2018-04-25 19:11:43,795:   File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 27, in setup
2018-04-25 19:11:43,795:     apps.populate(settings.INSTALLED_APPS)
2018-04-25 19:11:43,795: 
2018-04-25 19:11:43,795:   File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 85, in populate
2018-04-25 19:11:43,795:     app_config = AppConfig.create(entry)
2018-04-25 19:11:43,796: 
2018-04-25 19:11:43,796:   File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 94, in create
2018-04-25 19:11:43,796:     module = import_module(entry)

A similar problem happens when I try to import the rest_framework from my urls.py, but in the other hand when I import rest_framework with IPython -> "python manage.py shell" it works fine.
Any clue to solve this? Thanks

[edit by admin: formatting]

Are you sure that you've installed it for the right version of Python? Each version keeps its own set of installed packages, so pip install --user djangorestframework (which installs stuff for Python 2.7) won't install it for, say Python 3.6. You need to specify the Python version in the command, for example:

pip3.6 install --user djangorestframework

i am getting the same problem,please someone help, also getting ModuleNotFoundError: No module named 'django.urls'

that possibly sounds like an error with the wrong django version installed vs the code

I am facing the same problem Everything works on LocalHost but same code does not work on pythonanywhere.com. python version - Python 3.6.9 django version - 3.0.6 django rest framework version - 3.11.0.
What should i do now?

If you're using Django 3.0 then I recommend that you use a virtualenv for your website -- then you should use pip inside the virtualenv to install the djangorestframework package.