Answer the question
In order to leave comments, you need to log in
Why won't gunicorn start?
Trying to make an e-shop using mezzanine and Cartridge
Everything is going well:
virtualenv env
. env/bin/activate
pip install -U cartridge
mezzanine-project -a cartridge project
cd project/
python manage.py createdb --noinput
python manage.py runserver
.....
_d^^^^^^^^^b_
.d'' ``b.
.p' `q.
.d' `b.
.d' `b. * Mezzanine 3.1.10
:: :: * Django 1.6.8
:: M E Z Z A N I N E :: * Python 3.4.1
:: :: * SQLite 3.6.20
`p. .q' * Linux 2.6.32-504.el6.x86_64
`p. .q'
`b. .d'
`q.. ..p'
^q........p^
gunicorn wsgi
Error handling request
Traceback (most recent call last):
File "/home/test/env/lib/python3.4/site-packages/django/conf/__init__.py", line 128, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/test/env/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'project'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/test/env/lib/python3.4/site-packages/gunicorn/workers/sync.py", line 93, in handle
self.handle_request(listener, req, client, addr)
File "/home/test/env/lib/python3.4/site-packages/gunicorn/workers/sync.py", line 134, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/home/test/env/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
self.load_middleware()
File "/home/test/env/lib/python3.4/site-packages/django/core/handlers/base.py", line 44, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "/home/test/env/lib/python3.4/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/home/test/env/lib/python3.4/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/home/test/env/lib/python3.4/site-packages/django/conf/__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'project.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'project'
Answer the question
In order to leave comments, you need to log in
The problem is solved by adding 2 lines to the wsgi.py file
#####################
from __future__ import unicode_literals
import os
PROJECT_ROOT = os.path.dirname(os.path .abspath(__file__))
settings_module = "%s.settings" % PROJECT_ROOT.split(os. sep)[-1]
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
################### ##
I don't know how correct this is, but it works.
I stepped on the same rake, the problem is that gunicorn does not know where the modules are.
That is, you need to use modules either import {module_name}.{module}
in imports and everywhere.
Or I sys.path.append(PROJECT_ROOT)
tried to write both options, and they work. For a long time I could not understand the reason.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question