ModuleNotFoundError: No module named 'wsgi'
Asked Answered
A

4

11

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.

Anatollo answered 13/9, 2019 at 6:22 Comment(3)
Did you actually install wsgi?Silsbye
Your Procfile doesn't literally include -> prefixes to every line, does it? Please don't add useless decorations to things, especially when they reduce clarity.Character
And did you try the "things you tried" at the same time, in one Procfile with two lines?Character
C
15
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 :.

Character answered 13/9, 2019 at 12:26 Comment(0)
P
3

My 2c for people reading in the future

I had exact same issue,

web: gunicorn wsgi:app

expects that the wsgi.py file is in the project root, ie MyProject/ wsgi.py

but I had it in

MyProject/ app / wsgi.py

for which the correct command would (confusingly) be:

web: gunicorn app.wsgi:app
Portraitist answered 2/2, 2022 at 0:15 Comment(0)
G
-3

You have to create a procfile.txt in your root directory and just give your wsgi file path there.as- web: gunicorn config.wsgi

Granophyre answered 13/9, 2019 at 7:7 Comment(0)
D
-3

Don't save it as procfile.txt, that will result into more bug, the file should be saved as "Procfile" with no extension, i repeat no extension just the "Procfile" only and it should be in the root of your project

Debbidebbie answered 22/6, 2021 at 11:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.