Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gunicorn: No Module named 'wsgi'

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
like image 357
lathomas64 Avatar asked Jan 05 '18 20:01

lathomas64


3 Answers

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
like image 169
Slipstream Avatar answered Oct 23 '22 02:10

Slipstream


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?)

like image 29
ron rothman Avatar answered Oct 23 '22 02:10

ron rothman


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.

like image 31
erichiggins Avatar answered Oct 23 '22 03:10

erichiggins