2015-04-28 61 views
4

我试图使用Django设置芹菜。我也跟着指南:芹菜导入错误:没有模块名为凸出

项目/工程/ celery.py:

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) 

然后...

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 

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

from __future__ import absolute_import 

from celery import shared_task 


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

然后运行:

celery -A proj worker -l info

这给错误:

File "/Users/user/Documents/workspace/test-api/env/lib/python2.7/site-packages/kombu/utils/__init__.py", line 92, in symbol_by_name 
    module = imp(module_name, package=package, **kwargs) 
    File "/Users/user/Documents/workspace/test-api/env/lib/python2.7/site-packages/celery/utils/imports.py", line 101, in import_from_cwd 
    return imp(module, package=package) 
    File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module 
    __import__(name) 
ImportError: No module named proj 

回答

11

您的项目被命名为project,不proj。您应该使用在整个这个名字。

4

我只想说,如果你有正确命名的一切,你仍然有模块未找到错误(我花了几个小时试图弄清楚这一点)......然后,你必须将命令“芹菜-A PROJ工人-l信息”上面的应用程序分支

‘芹菜程序可用于启动工作(你需要运行在上面凸出的目录工人):’按照该文档

+0

是啊,一切celery-相关始终保证给我头疼。你得佩服它得到执行,但是孩子是一件很痛苦的总是追逐的配置问题。 –

相关问题