首页 > 解决方案 > 无法启动工人,没有名为“芹菜”的模块

问题描述

我尝试在我的 web 应用程序中包含任务,但我无法启动 celery 工作。

我的项目结构如下:

网站/网站 --> init.py、settings.py、urls.py、wsgi.py

网站/索引 --> init.py、celery_app.py、tasks.py

索引是我要运行任务的起始页。

index/celery_app.py有以下代码:

from __future__ import absolute_import, unicode_literals
from celery import Celery

app = Celery('index',
         broker='amqp://localhost//',
         backend='amqp://',
         include=['index.tasks'])

 # Optional configuration, see the application user guide.
 app.conf.update(
    result_expires=3600,
   )

if __name__ == '__main__':
app.start()

索引/tasks.py

from __future__ import  absolute_import
from .celery_app import app

@app.task
def test_func():
    print("Test Background Task")

当我想用celery -A index worker --loglevel=info启动 worker 时,我收到以下错误:ModuleNotFoundError: No module named 'celery'。我在索引文件夹中运行命令提示符。

类似问题中的其他解决方案对我没有帮助。

我的包裹截图:已安装的软件包

标签: pythondjangocelery

解决方案


只写

    app = Celery(
    "SARyS",
    broker='pyamqp://guest:guest@rabbitmq.insertmendoza.com.ar',
    include=["SARyS.Apps.TaskManager.Tasks"]
)

推荐阅读