Gunicorn ImportError:没有名为polls

时间:2018-04-12 02:03:44

标签: python django gunicorn

我正在使用gunicorn和nginx在新服务器上安装以前构建的Django网站。

/home/ragequittech/manage.py runserver运行正常但是,当我关闭它并运行/home/rageqquittech/ragequittech gunicorn --bind 0.0.0.0:8030 wsgi:application时,我得到了:

[2018-04-12 01:36:06 +0000] [1842] [INFO] Starting gunicorn 19.4.5
[2018-04-12 01:36:06 +0000] [1842] [INFO] Listening at: http://0.0.0.0:8030 (1842)
[2018-04-12 01:36:06 +0000] [1842] [INFO] Using worker: sync
[2018-04-12 01:36:06 +0000] [1846] [INFO] Booting worker with pid: 1846
[2018-04-11 20:36:06 +0000] [1846] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 366, in import_app
    __import__(module)
  File "/home/ragequittech/ratequittech/wsgi.py", line 21, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 94, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named polls
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 366, in import_app
    __import__(module)
  File "/home/ragequittech/ratequittech/wsgi.py", line 21, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 94, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named polls
[2018-04-11 20:36:06 +0000] [1846] [INFO] Worker exiting (pid: 1846)
[2018-04-12 01:36:06 +0000] [1842] [INFO] Shutting down: Master
[2018-04-12 01:36:06 +0000] [1842] [INFO] Reason: Worker failed to boot.

wsgi.py

import sys

from django.core.wsgi import get_wsgi_application

path = '/home/ragequittech/ragequittech/'
if path not in sys.path:
    sys.path.append(path)

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

application = get_wsgi_application()

print sys.path

get_wsgi_application()之前附加wsgi.py的输出
gunicorn --bind 0.0.0.0:8030 wsgi:application
[2018-04-14 20:55:44 +0000] [21821] [INFO] Starting gunicorn 19.4.5
[2018-04-14 20:55:44 +0000] [21821] [INFO] Listening at: http://0.0.0.0:8030 (21821)
[2018-04-14 20:55:44 +0000] [21821] [INFO] Using worker: sync
[2018-04-14 20:55:44 +0000] [21825] [INFO] Booting worker with pid: 21825
['/home/ragequittech/ratequittech', '/usr/bin', '/home/ragequittech/polls', '/home/ragequittech/home', '/home/ragequittech/blog', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/home/ragequittech/ragequittech/']
[2018-04-14 15:55:44 +0000] [21825] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 366, in import_app
    __import__(module)
  File "/home/ragequittech/ratequittech/wsgi.py", line 23, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 94, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named polls
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 366, in import_app
    __import__(module)
  File "/home/ragequittech/ratequittech/wsgi.py", line 23, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 94, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named polls
[2018-04-14 15:55:44 +0000] [21825] [INFO] Worker exiting (pid: 21825)
[2018-04-14 20:55:44 +0000] [21821] [INFO] Shutting down: Master
[2018-04-14 20:55:44 +0000] [21821] [INFO] Reason: Worker failed to boot.
来自 settings.py

摘录:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'ckeditor',
    'ckeditor_uploader',
    'polls',
    'home',
    'blog',
    'podcast',
]

这些应用程序存在于/home/ragequittech/目录中。我认为它可能是python路径的一个问题,但似乎没有帮助。我在民意调查应用程序中包含了以下setup.py并运行python setup.py develop,但这也无济于事:

setup.py

#!/usr/bin/env python
from setuptools import setup, find_packages

setup(name='polls',
      version='1.0',
      packages=find_packages())

我知道问题是应用程序没有“安装”,但我找不到合适的方法来缓解它。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

如果您的应用程序存在于/home/ragequittech目录中,请确保在开始使用gunicorn之前该应用程序位于PYTHONPATH

export PYTHONPATH=/home/ragequittech

好像wsgi.py模块位于/home/ragequittech/ragequittech子目录中。因此,请确保在运行gunicorn命令时完全限定wsgi.py,并从顶级目录运行它。

# Start from /home/ragequittech, and note qualified name
gunicorn --bind 0.0.0.0:8030 ragequittech.wsgi:application