使用 Django 1.8 和 python 3.4 的 gunicorn 中没有名为“project”的模块

使用 Django 1.8 和 python 3.4 的 gunicorn 中没有名为“project”的模块

我已经使用 ansible 在 vi​​rtualenv 文件夹中部署了一个使用 Django 1.8 和 python3.4 的项目。对于我的项目(包括配置文件夹中的设置和 wsgi),它可以正常工作,部署正常并且有效。对于我的项目(设置和 wsgi 位于项目根目录中),则不行。

Nginx 运行良好。问题出在 gunicorn 和 Supervisor 上no module named '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

主管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

我的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

我的wsgi.py:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我不知道为什么会遇到这个问题。Supervisor 一直在徒劳地重启项目。

错误输出如下: [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.

相关内容