ModuleNotFoundError: No module named 'wsgi'

killer whale picture killer whale · Sep 13, 2019 · Viewed 11k times · Source

I was going to host it using Heroku. But it does not work because of the problem with the profile.

This my Procfile

-> web: gunicorn wsgi:app

I tried these things.

->web : gunicorn wsgi.py
->web : gunicorn <myproject>.wsgi --log-file-

my wsgi.py code

"""
WSGI config for config 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.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

application = get_wsgi_application()


from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)

this is my heroku log

Starting process with command gunicorn wsgi:app 2019-09-13T06:06:27.409894+00:00 heroku[web.1]: State changed from starting to crashed 2019-09-13T06:06:27.388714+00:00 heroku[web.1]: Process exited with status 3 2019-09-13T06:06:27.176179+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [4] [INFO] Starting gunicorn 19.9.0 2019-09-13T06:06:27.177866+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [4] [INFO] Listening at: http://0.0.0.0:56276 (4) 2019-09-13T06:06:27.177959+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [4] [INFO] Using worker: sync 2019-09-13T06:06:27.181907+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [10] [INFO] Booting worker with pid: 10 2019-09-13T06:06:27.187052+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [11] [INFO] Booting worker with pid: 11 2019-09-13T06:06:27.187674+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [10] [ERROR] Exception in worker process 2019-09-13T06:06:27.187678+00:00 app[web.1]: Traceback (most recent call last): 2019-09-13T06:06:27.187680+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker 2019-09-13T06:06:27.187682+00:00 app[web.1]: worker.init_process() 2019-09-13T06:06:27.187684+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process 2019-09-13T06:06:27.187686+00:00 app[web.1]: self.load_wsgi() 2019-09-13T06:06:27.187688+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi 2019-09-13T06:06:27.187690+00:00 app[web.1]: self.wsgi = self.app.wsgi() 2019-09-13T06:06:27.187692+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi 2019-09-13T06:06:27.187694+00:00 app[web.1]: self.callable = self.load() 2019-09-13T06:06:27.187696+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load 2019-09-13T06:06:27.187698+00:00 app[web.1]: return self.load_wsgiapp() 2019-09-13T06:06:27.187700+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp 2019-09-13T06:06:27.187702+00:00 app[web.1]: return util.import_app(self.app_uri) 2019-09-13T06:06:27.187704+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app 2019-09-13T06:06:27.187706+00:00 app[web.1]: import(module) 2019-09-13T06:06:27.187708+00:00 app[web.1]: ModuleNotFoundError: No module named 'wsgi' 2019-09-13T06:06:27.187851+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [10] [INFO] Worker exiting (pid: 10) 2019-09-13T06:06:27.193919+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [11] [ERROR] Exception in worker process 2019-09-13T06:06:27.193924+00:00 app[web.1]: Traceback (most recent call last): 2019-09-13T06:06:27.193926+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker 2019-09-13T06:06:27.193928+00:00 app[web.1]: worker.init_process() 2019-09-13T06:06:27.193930+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process 2019-09-13T06:06:27.193932+00:00 app[web.1]: self.load_wsgi() 2019-09-13T06:06:27.193934+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi 2019-09-13T06:06:27.193936+00:00 app[web.1]: self.wsgi = self.app.wsgi() 2019-09-13T06:06:27.193939+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi 2019-09-13T06:06:27.193941+00:00 app[web.1]: self.callable = self.load() 2019-09-13T06:06:27.193943+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load 2019-09-13T06:06:27.193945+00:00 app[web.1]: return self.load_wsgiapp() 2019-09-13T06:06:27.193947+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp 2019-09-13T06:06:27.193949+00:00 app[web.1]: return util.import_app(self.app_uri) 2019-09-13T06:06:27.193951+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app 2019-09-13T06:06:27.193953+00:00 app[web.1]: import(module) 2019-09-13T06:06:27.193955+00:00 app[web.1]: ModuleNotFoundError: No module named 'wsgi' 2019-09-13T06:06:27.194099+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [11] [INFO] Worker exiting (pid: 11) 2019-09-13T06:06:27.321586+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [4] [INFO] Shutting down: Master 2019-09-13T06:06:27.321719+00:00 app[web.1]: [2019-09-13 06:06:27 +0000] [4] [INFO] Reason: Worker failed to boot.

Answer

Chris picture Chris · Sep 13, 2019
web: gunicorn wsgi:app

This almost certainly isn't correct.

The arguments passed to gunicorn tell it where your application's entry point is. It matches your Python module path. Typically, this would be the file called wsgi.py inside your project directory:

myproject/
    wsgi.py

Therefore your Procfile should contain

web: gunicorn myproject.wsgi

Make sure to follow this format exactly. There shouldn't be a space between web and :.