我正在尝试使用nginx和Gunicorn设置现有的Django应用程序。在完成我的nginx设置和测试之前,我只是尝试使用gunicorn
进行测试。当我尝试运行gunicorn
命令时出现以下错误:
(venv)me@mymachine:/srv/test/proj$ gunicorn --bind 0.0.0.0:8001 myapp.wsgi
[2015-09-18 09:40:30 -0400] [18838] [INFO] Starting gunicorn 19.3.0
[2015-09-18 09:40:30 -0400] [18838] [INFO] Listening at: http://0.0.0.0:8001 (18838)
[2015-09-18 09:40:30 -0400] [18838] [INFO] Using worker: sync
[2015-09-18 09:40:30 -0400] [18841] [INFO] Booting worker with pid: 18841
/srv/test/venv/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: The django.forms.util module has been renamed. Use django.forms.utils instead.
return f(*args, **kwds)
[2015-09-18 09:40:31 -0400] [18841] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/test/venv/lib/python3.4/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
worker.init_process()
File "/srv/test/venv/lib/python3.4/site-packages/gunicorn/workers/base.py", line 118, in init_process
self.wsgi = self.app.wsgi()
File "/srv/test/venv/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/srv/test/venv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/srv/test/venv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/srv/test/venv/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
__import__(module)
File "/srv/test/proj/myapp/wsgi.py", line 30, in <module>
application = get_wsgi_application()
File "/srv/test/venv/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/srv/test/venv/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/srv/test/venv/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/srv/test/venv/lib/python3.4/site-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/srv/test/venv/lib/python3.4/site-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/srv/test/venv/lib/python3.4/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/srv/test/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/srv/test/proj/request/admin.py", line 6, in <module>
from resource.models import ResourceRequest
ImportError: No module named 'resource.models'; 'resource' is not a package
然而该文件确实存在并被设置为包。我甚至可以做runserver
并且开发服务器正确启动,出现0错误。
这是我的wsgi.py:
"""
WSGI config for myapp project.
"""
import os
from django.core.wsgi import get_wsgi_application
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "myapp.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
application = get_wsgi_application()
我搜索了高低,stackoverflow或其他网站的答案都没有帮助。我在python2和python3环境中都试过这个。
我也尝试过:
gunicorn --bind 0.0.0.0:8001 myapp.wsgi:application
和
gunicorn --env DJANGO_SETTINGS_MODULE=myapp.settings myapp.wsgi:application
两者都有相同的错误。
问题是什么?
编辑:我认为这是错误的关键部分:[2015-09-18 10:30:32 -0400] [19235] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
这是Gunicorn的一个错误吗?
答案 0 :(得分:0)
想出来了。单词resource
显然是Gunicorn的某种名称冲突。必须重命名我的应用以及resources
的所有引用来修复它。
等等...