I've deployed with ansible a project using Django 1.8 and python3.4 in a virtualenv folder. For my projects including settings and wsgi in a config folder it works, the deployment is fine and it works. For my project where settings and wsgi are in the project root directory, it doesn't.
Nginx works fine. It's gunicorn with supervisor that scratch with a no module named 'project'
issue.
here is the layout of my project:
├── gunicorn.conf.py
├── gunicorn.log
├── nginx-access.log
├── nginx-error.log
└── project
├── contributors.txt
├── __init__.py
├── manage.py
├── rdt_theme
├── README.md
├── requirements.txt
├── settings.py
├── static
├── urls.py
└── wsgi.py
Supervisor conf.d:
[program:gunicorn_rdtfront]
command=/opt/.virtualenvs/rdtfront/bin/gunicorn wsgi -c /opt/www/rdtfront/gunicorn.conf.py
directory=/opt/www/rdtfront/project
user=rdtfront
autostart=true
autorestart=true
redirect_stderr=True
stdout_logfile=/opt/www/rdtfront/gunicorn.log
stderr_logfile=/opt/www/rdtfront/gunicorn.log
My gunicorn.conf.py:
import multiprocessing
bind = "unix:///tmp/rdtfront.sock"
workers = multiprocessing.cpu_count() * 2 + 1
user = 'rdtfront'
logfile = "/opt/www/rdtfront/gunicorn.log"
loglevel = "info"
pidfile = '/tmp/rdtfront.pid'
daemon = False
debug = False
timeout = 300
And my wsgi.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I can't figure out why I'm getting this issue. Supervisor keeps restarting the project in vain.
Below the error output:
[2015-06-26 17:06:06 +0200] [451] [INFO] Worker exiting (pid: 451)
[2015-06-26 17:06:06 +0200] [452] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 394, in urlconf_module
return self._urlconf_module
AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
worker.init_process()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/workers/base.py", line 118, in init_process
self.wsgi = self.app.wsgi()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
__import__(module)
File "/opt/www/rdtfront/project/wsgi.py", line 9, in <module>
application = get_wsgi_application()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/debug_toolbar/apps.py", line 15, in ready
dt_settings.patch_all()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/debug_toolbar/settings.py", line 232, in patch_all
patch_root_urlconf()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/debug_toolbar/settings.py", line 220, in patch_root_urlconf
reverse('djdt:render_panel')
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 550, in reverse
app_list = resolver.app_dict[ns]
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 352, in app_dict
self._populate()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 285, in _populate
for pattern in reversed(self.url_patterns):
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 402, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 396, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/opt/.virtualenvs/rdtfront/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named 'project'
Traceback (most recent call last):
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 394, in urlconf_module
return self._urlconf_module
AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
worker.init_process()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/workers/base.py", line 118, in init_process
self.wsgi = self.app.wsgi()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
__import__(module)
File "/opt/www/rdtfront/project/wsgi.py", line 9, in <module>
application = get_wsgi_application()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/debug_toolbar/apps.py", line 15, in ready
dt_settings.patch_all()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/debug_toolbar/settings.py", line 232, in patch_all
patch_root_urlconf()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/debug_toolbar/settings.py", line 220, in patch_root_urlconf
reverse('djdt:render_panel')
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 550, in reverse
app_list = resolver.app_dict[ns]
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 352, in app_dict
self._populate()
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 285, in _populate
for pattern in reversed(self.url_patterns):
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 402, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/opt/.virtualenvs/rdtfront/lib/python3.4/site-packages/django/core/urlresolvers.py", line 396, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/opt/.virtualenvs/rdtfront/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named 'project'
[2015-06-26 17:06:06 +0200] [452] [INFO] Worker exiting (pid: 452)
/opt/.virtualenvs/rdtfront/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.