0

I am running a web application. It is working in my local development server without any error but when I deployed it to Heroku, it has to build successfully. When I opened my application URL then it is giving application error. After viewing Heroku logs I found it is saying that ModuleNotFoundError.

here is the complete log of Heroku:

2020-04-15T04:37:07.706710+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2020-04-15T04:37:07.706715+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 342, in halt
2020-04-15T04:37:07.706919+00:00 app[web.1]: self.stop()
2020-04-15T04:37:07.706920+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
2020-04-15T04:37:07.707137+00:00 app[web.1]: time.sleep(0.1)
2020-04-15T04:37:07.707141+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-04-15T04:37:07.707307+00:00 app[web.1]: self.reap_workers()
2020-04-15T04:37:07.707311+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-04-15T04:37:07.707552+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-04-15T04:37:07.707581+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-04-15T04:37:09.000000+00:00 app[api]: Build succeeded
2020-04-15T04:37:14.867490+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-15T04:37:14.641214+00:00 app[web.1]: [2020-04-15 04:37:14 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-04-15T04:37:14.641835+00:00 app[web.1]: [2020-04-15 04:37:14 +0000] [4] [INFO] Listening at: http://0.0.0.0:37686 (4)
2020-04-15T04:37:14.641995+00:00 app[web.1]: [2020-04-15 04:37:14 +0000] [4] [INFO] Using worker: sync
2020-04-15T04:37:14.646404+00:00 app[web.1]: [2020-04-15 04:37:14 +0000] [10] [INFO] Booting worker with pid: 10
2020-04-15T04:37:14.663560+00:00 app[web.1]: [2020-04-15 04:37:14 +0000] [10] [ERROR] Exception in worker process
2020-04-15T04:37:14.663563+00:00 app[web.1]: Traceback (most recent call last):
2020-04-15T04:37:14.663580+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-04-15T04:37:14.663581+00:00 app[web.1]: worker.init_process()
2020-04-15T04:37:14.663581+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-04-15T04:37:14.663581+00:00 app[web.1]: self.load_wsgi()
2020-04-15T04:37:14.663581+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-04-15T04:37:14.663582+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-04-15T04:37:14.663582+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-04-15T04:37:14.663582+00:00 app[web.1]: self.callable = self.load()
2020-04-15T04:37:14.663583+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-04-15T04:37:14.663583+00:00 app[web.1]: return self.load_wsgiapp()
2020-04-15T04:37:14.663583+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-04-15T04:37:14.663583+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-04-15T04:37:14.663584+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2020-04-15T04:37:14.663584+00:00 app[web.1]: mod = importlib.import_module(module)
2020-04-15T04:37:14.663584+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-04-15T04:37:14.663584+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-04-15T04:37:14.663585+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-04-15T04:37:14.663585+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-04-15T04:37:14.663585+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
2020-04-15T04:37:14.663636+00:00 app[web.1]: ModuleNotFoundError: No module named 'django.wsgi'
2020-04-15T04:37:14.663794+00:00 app[web.1]: [2020-04-15 04:37:14 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-04-15T04:37:14.702203+00:00 app[web.1]: [2020-04-15 04:37:14 +0000] [11] [INFO] Booting worker with pid: 11
2020-04-15T04:37:14.714301+00:00 app[web.1]: [2020-04-15 04:37:14 +0000] [11] [ERROR] Exception in worker process
2020-04-15T04:37:14.714303+00:00 app[web.1]: Traceback (most recent call last):
2020-04-15T04:37:14.714304+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-04-15T04:37:14.714305+00:00 app[web.1]: worker.init_process()
2020-04-15T04:37:14.714305+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-04-15T04:37:14.714306+00:00 app[web.1]: self.load_wsgi()
2020-04-15T04:37:14.714306+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-04-15T04:37:14.714311+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-04-15T04:37:14.714312+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-04-15T04:37:14.714312+00:00 app[web.1]: self.callable = self.load()
2020-04-15T04:37:14.714312+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-04-15T04:37:14.714313+00:00 app[web.1]: return self.load_wsgiapp()
2020-04-15T04:37:14.714313+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-04-15T04:37:14.714314+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-04-15T04:37:14.714314+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2020-04-15T04:37:14.714314+00:00 app[web.1]: mod = importlib.import_module(module)
2020-04-15T04:37:14.714315+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-04-15T04:37:14.714315+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-04-15T04:37:14.714315+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-04-15T04:37:14.714316+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-04-15T04:37:14.714316+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
2020-04-15T04:37:14.714317+00:00 app[web.1]: ModuleNotFoundError: No module named 'django.wsgi'
2020-04-15T04:37:14.714402+00:00 app[web.1]: [2020-04-15 04:37:14 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-04-15T04:37:14.749177+00:00 app[web.1]: Traceback (most recent call last):
2020-04-15T04:37:14.749250+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 202, in run
2020-04-15T04:37:14.749728+00:00 app[web.1]: self.manage_workers()
2020-04-15T04:37:14.749786+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 545, in manage_workers
2020-04-15T04:37:14.750283+00:00 app[web.1]: self.spawn_workers()
2020-04-15T04:37:14.750338+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 617, in spawn_workers
2020-04-15T04:37:14.750811+00:00 app[web.1]: time.sleep(0.1 * random.random())
2020-04-15T04:37:14.750865+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-04-15T04:37:14.751141+00:00 app[web.1]: self.reap_workers()
2020-04-15T04:37:14.751173+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-04-15T04:37:14.751578+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-04-15T04:37:14.751669+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-04-15T04:37:14.751697+00:00 app[web.1]:
2020-04-15T04:37:14.751697+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-04-15T04:37:14.751698+00:00 app[web.1]:
2020-04-15T04:37:14.751724+00:00 app[web.1]: Traceback (most recent call last):
2020-04-15T04:37:14.751752+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 8, in <module>
2020-04-15T04:37:14.751960+00:00 app[web.1]: sys.exit(run())
2020-04-15T04:37:14.751964+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
2020-04-15T04:37:14.752125+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2020-04-15T04:37:14.752146+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 228, in run
2020-04-15T04:37:14.752379+00:00 app[web.1]: super().run()
2020-04-15T04:37:14.752381+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
2020-04-15T04:37:14.752541+00:00 app[web.1]: Arbiter(self).run()
2020-04-15T04:37:14.752544+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 229, in run
2020-04-15T04:37:14.752787+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2020-04-15T04:37:14.752825+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 342, in halt
2020-04-15T04:37:14.753174+00:00 app[web.1]: self.stop()
2020-04-15T04:37:14.753179+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
2020-04-15T04:37:14.753521+00:00 app[web.1]: time.sleep(0.1)
2020-04-15T04:37:14.753522+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-04-15T04:37:14.753684+00:00 app[web.1]: self.reap_workers()
2020-04-15T04:37:14.753685+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-04-15T04:37:14.753948+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-04-15T04:37:14.753965+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-04-15T04:37:39.748448+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=quiz-appclay.herokuapp.com request_id=149d55b1-c0e6-4cb1-a73a-da6ce23b1106 fwd="47.8.143.12" dyno= connect= service= status=503 bytes= protocol=https
2020-04-15T04:37:42.430171+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=quiz-appclay.herokuapp.com request_id=40ef987a-e061-4b71-86b0-6d8c74956331 fwd="47.8.143.12" dyno= connect= service= status=503 bytes= protocol=https

It is the complete log file. And here is my wsgi.py file:

"""
WSGI config for django_school project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_school.settings")

application = get_wsgi_application()

Below is the file structure of my project: file structure

  • How did you install django, and in what specific directory was it installed? – John Gordon Apr 15 '20 at 05:15
  • This is probably due to configuration mismatch, i have similar experience with pythonanywhere, would suggest you recheck the path to wsgi.py specified on heroku. – Ansuman Apr 15 '20 at 06:35
  • You don't usually need to change the `wsgi.py` in a Django project, so that probably isn't what the problem is. Please show your `Procfile`, and the layout of the files in your project (in particular where the `Procfile` and `wsgi.py` are located relative to each other). – Alasdair Apr 15 '20 at 08:23
  • @ansuman I have specified the same path. – Rohit Singh Apr 15 '20 at 09:17
  • @JohnGordon I had installed Django in my venv using `pip install django`. – Rohit Singh Apr 15 '20 at 09:21
  • @Alasdair I have added the layout of my project in the last of my question. Please have a look. – Rohit Singh Apr 15 '20 at 09:28
  • Your wsgi file is in the `django_school` directory, so your `Procfile` should use `django_school.wsgi`, not `django.wsgi`. Change the `Procfile` to `web: gunicorn django_school.wsgi:application --python django_school`. The `--python django_school` part is required because your project isn't in the top level of the repo alongside the `Procfile`, see the related question for more info. – Alasdair Apr 15 '20 at 10:03
  • 1
    Thanks @Alasdair. It worked and has solved my issue. :) – Rohit Singh Apr 15 '20 at 13:03

0 Answers0