I'm trying to connect Gunicorn to my Django application, by Docker, to serve it as an HTTP server. The build was successful, with no errors. My problem starts in the race. That's the kind of message I get:
[2020-10-01 12:55:18 +0000] [9] [INFO] Starting gunicorn 20.0.4
[2020-10-01 12:55:18 +0000] [9] [INFO] Listening at: http://0.0.0.0:8010 (9)
[2020-10-01 12:55:18 +0000] [9] [INFO] Using worker: sync
[2020-10-01 12:55:18 +0000] [13] [INFO] Booting worker with pid: 13
[2020-10-01 12:55:18 +0000] [13] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
mod = importlib.import_module(module)
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'wsgi'
[2020-10-01 12:55:18 +0000] [13] [INFO] Worker exiting (pid: 13)
[2020-10-01 12:55:18 +0000] [9] [INFO] Shutting down: Master
[2020-10-01 12:55:18 +0000] [9] [INFO] Reason: Worker failed to boot.
I know that there are several issues with this same doubt, but I have not been successful in reading them and would like another point of view. The error says that the WSGI module was not found, and I don't know why it can't find it. I believe it is a PATH problem.
This is my tree:
Myproject
├───.pip_cache
├───.vscode
├───backups
├───general_app
│ ├───migrations
│ │ └───__pycache__
│ └───__pycache__
├───headers
├───sistem
│ └───__pycache__
│ └───wsgi.py
│ └───urls.py
│ └───settings.py
│ └───asgi.py
├───sistema.egg-info
└───app
├───migrations
│ └───__pycache__
├───util
└───__pycache__
And this is my command on docker to run gunicorn:
(cd .. && gunicorn wsgi:app --user www-data --bind 0.0.0.0:8010 --workers 3) &
nginx -g "daemon off;"
I just try to do this:
(cd .. && gunicorn sistem.wsgi:app --user www-data --bind 0.0.0.0:8010 --workers 3) &
nginx -g "daemon off;"
But the error change to:
ModuleNotFoundError: No module named 'sistem'
I don't understand what may be going on.