python - Django celery 导入错误 : no module named celery when using gunicorn bind?

标签 python django command-line celery gunicorn

我一直在到处寻找这个问题的答案。我正在 Ubuntu 16.04( digital ocean )上为我的 Django 网站设置服务器,我的 Django 网站需要使用 celery 来完成一些周期性任务。

它适用于我的开发环境。运行 python manage.py celery beatpython manage.py celery worker 工作得很好。它也全部安装在 virtualenv 中。

这是我的文件:

# __init__.py

from __future__ import absolute_import
from .celery_tasks import app as celery_app  # noqa

#celery_tasks.py

from __future__ import absolute_import

import os
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')

from django.conf import settings  # noqa

app = Celery('myproject')

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

这是一直在发生的错误:

# gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application

File "/root/myproject/myproject/__init__.py", line 2, in <module>
from .celery_tasks import app as celery_app  # noqa
File "/root/myproject/myproject/celery_tasks.py", line 4, in <module>
from celery import Celery
ImportError: No module named celery
[2017-08-13 07:29:36 +0000] [5463] [INFO] Worker exiting (pid: 5463)
[2017-08-13 07:29:36 +0000] [5458] [INFO] Shutting down: Master
[2017-08-13 07:29:36 +0000] [5458] [INFO] Reason: Worker failed to boot.

还有一些看起来不太相关的追溯。

非常感谢任何帮助。我想我错过了一些简单的东西,但我已经为此苦苦挣扎了几个小时。

最佳答案

错误说不是创建 celery 。 所以将 celery 放在你的 requirements.txt 文件中,当你部署它时安装 Celery。 或者在你的服务器上做:

pip install celery

或在您的 requirements.txt 中插入 celery 并执行:

pip install -r requirements.txt

关于python - Django celery 导入错误 : no module named celery when using gunicorn bind?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45658156/

相关文章:

python - python中有枚举器查找方法吗?

python - 尝试从数据库更新现有行时,Django 表单未验证

python - Django - 格式化日期以从表单更新模型对象

python - 使用 VS2013 的 python 工具时,Django 不会延迟加载

java - Eclipse 项目是否编译?

c - 获取 Dev-C++ 构建的程序以将 UNICODE 字符输出到 Windows 命令行

python - Pytorch 训练和评估不同的样本量

python - 如何使用 python 分割大型 CSS 文件?

bash - 递归移动某种类型的文件并保持其目录结构

python - python 2.7 urllib2 和 json 中的脚本引发 unicode 错误