0

Adding djoser to my Django app and doing all tests on localhost it works fine. Yet after restarting apache2 (app was already added to apache and working fine), it is giving Internal Server Error 500.

Have looked around of what is going on and following these instructions to get an actual error.

The following is produced

Traceback (most recent call last):
  File "<path_to_app>/wsgi.py", line 21, in <module>
    application = get_wsgi_application()
  File "<path_to_app>/env/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "<path_to_app>/env/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "<path_to_app>/env/lib/python3.6/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "<path_to_app>/env/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'djoser'
mod_wsgi (pid=7989): Target WSGI script '<path_to_app>/wsgi.py' does not contain WSGI application 'application'.
mod_wsgi (pid=8126): Target WSGI script '<path_to_app>/wsgi.py' does not contain WSGI application 'application'.

I have no idea why it is saying no module named 'djoser', python/pip tells me it is installed and it is working on localhost.

punjabi4life
  • 655
  • 1
  • 9
  • 22

1 Answers1

1

I have seen similar errors after a

$ sudo apachectl graceful 

but they went away after a full

$ sudo apachectl restart

That could be worth trying.

Edited to include actual solution from comments:

Also, check your python path. Where is djoser? I once had issues with modules installing to dist-packages vs site-packages. And with virtual environments or different users it is possible for Apache to be using a different python path to what you are using when you run the development server.

Mark Bailey
  • 1,617
  • 1
  • 7
  • 13
  • Tried this, did not have any effect. Still receiving same error – punjabi4life Aug 30 '19 at 20:53
  • Also worth looking at your python path. Where is djoser? I once had issues with modules installing to dist-packages vs site-packages. – Mark Bailey Aug 30 '19 at 21:20
  • if it installed into a different location, how would it work fine on localhost vs live site? – punjabi4life Aug 30 '19 at 22:21
  • It is possible for apache to be using a different python path to what you are using when you run the development server. – Mark Bailey Aug 30 '19 at 22:40
  • Yup that was it, the apache was set to the virtual env for the project and the python for python being used in the virtual env was broken. That fixed the issue after repairing the path. If you want to update you answer with this info I will be more than happy to accept it. Thanks! – punjabi4life Aug 31 '19 at 17:16