Celery ImportError:没有名为proj的模块

时间:2015-04-28 13:31:11

标签: python django celery

我正在尝试用Django设置Celery。我遵循了指南:

项目/项目/ celery.py:

library(data.table)
DT <- data.table(xy)
tail(DT[, Count := .N, by = c("x", "y")][ order(Count) ], 1)
    x y Count
 1: 1 1     2

然后在......

from __future__ import absolute_import

import os

from celery import Celery

from django.conf import settings

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

app = Celery('proj')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

项目/应用/测试/ tasks.py

project/project/__init__.py:


from __future__ import absolute_import

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

然后运行:

  

celery -A proj worker -l info

给出错误:

from __future__ import absolute_import

from celery import shared_task


@shared_task
def add(x, y):
    return x + y

2 个答案:

答案 0 :(得分:14)

您的项目名为project,而不是proj。你应该始终使用该名称。

答案 1 :(得分:12)

我只是想说,如果你已经正确命名了所有内容并且你仍然找不到模块错误(我花了好几个小时试图解决这个问题)...那么你必须放置命令“celery -A proj worker - l信息“在应用程序分支上方

“celery程序可以用来启动worker(你需要在proj上面的目录中运行worker):”按照文档