gunicorn: No Module named 'wsgi'
Asked Answered
P

4

14

I have a project that is set up to run with docker One one machine which is ubuntu I have been running it fine but recently I have tried to run it on my windows laptop and am getting a ModuleNotFoundError.

[2018-01-05 20:31:46 +0000] [5] [INFO] Starting gunicorn 19.7.1
explore_1   | [2018-01-05 20:31:46 +0000] [5] [INFO] Listening at: http://0.0.0.0:8080 (5)
explore_1   | [2018-01-05 20:31:46 +0000] [5] [INFO] Using worker: sync
explore_1   | [2018-01-05 20:31:46 +0000] [8] [INFO] Booting worker with pid: 8
explore_1   | [2018-01-05 20:31:46 +0000] [8] [ERROR] Exception in worker process
explore_1   | Traceback (most recent call last):
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
explore_1   |     worker.init_process()
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 126, in init_process
explore_1   |     self.load_wsgi()
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
explore_1   |     self.wsgi = self.app.wsgi()
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
explore_1   |     self.callable = self.load()
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
explore_1   |     return self.load_wsgiapp()
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
explore_1   |     return util.import_app(self.app_uri)
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 352, in import_app
explore_1   |     __import__(module)
explore_1   | ModuleNotFoundError: No module named 'wsgi'
explore_1   | [2018-01-05 20:31:46 +0000] [8] [INFO] Worker exiting (pid: 8)
explore_1   | [2018-01-05 20:31:47 +0000] [5] [INFO] Shutting down: Master
explore_1   | [2018-01-05 20:31:47 +0000] [5] [INFO] Reason: Worker failed to boot.

I checked to make sure my environment variables for paths are set up correctly. Are there any common gunicorn issues that may cause this or other things that stand out as obvious checks?

The dockerfile for this container is as follows:

FROM python:3
MAINTAINER [email protected]
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /usr/src/app
ENV MODE dev
EXPOSE 8080
VOLUME /static
COPY src/static /static
RUN python3 setup.py install
#CMD python3 wsgi.py
CMD gunicorn -w 3 -b 0.0.0.0:8080 wsgi --reload
Palingenesis answered 5/1, 2018 at 20:47 Comment(4)
Apparently there is no file called wsgi.py? what is in /usr/src/app in the docker container?Solstice
after some tooling with the dockerfile it looks like COPY . /usr/src/app is not copying the wsgi.py up even though it is in the same directory as the dockerfile. not sure why this behavior would be different between docker on linux and docker on windows though.Palingenesis
Check your versions of docker, they may differ between windows and linux.Christiansen
I have seen this pattern of keeping the wsgi.py (file/module) in app folder. since you are doing COPY . /usr/src/app and if I assume wsgi.py file is present in at /usr/src/app/wsgi.py then all you need to do is add WORKDIR /usr/src/app before the last line. making wsgi.py available at base location.Sickly
C
15

To change to the project folder you can use the command --chdir.
Example:

gunicorn -w 2 -b 0.0.0.0:8000 --chdir /code/myproject myproject.wsgi
Clause answered 12/7, 2018 at 14:9 Comment(0)
A
5

You're asking gunicorn to run either a file name wsgi.py in your current directory, or a module named wsgi. The latter could simply be a directory named wsgi/ which includes an __init__.py file (therefore you'd need wsgi/__init__.py.

If your web application is contained in a file with a different name, you'll need to adjust the gunicorn command from wsgi to whatever it is.

Since it looks like you're using Docker to run this, it's also possible that you didn't use the ADD command within your Dockerfile to copy your wsgi.py file into your Docker container. Alternatively, you may have done that, but it's in a different directory than the one you're running the gunicorn command from.

Aldred answered 5/1, 2018 at 21:26 Comment(0)
C
4

Change this:

CMD gunicorn -w 3 -b 0.0.0.0:8080 wsgi --reload

to this:

CMD gunicorn -w 3 -b 0.0.0.0:8080 /full/path/to/wsgi --reload

where /full/path/to/wsgi is the absolute path of your app--I'm guessing it's /usr/src/app/wsgi?)

Christiansen answered 5/1, 2018 at 21:27 Comment(0)
E
0

It looks like you don't have the wsgi.py file.
I just added it by making the wsgi.py file and putting this to the file:

from application import app

if __name__ == '__main__':
    app.run(debug=False)
Entremets answered 28/6, 2022 at 3:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.