简体   繁体   English

Django芹菜找不到芹菜模块

[英]Django celery not finding celery module

I'm trying to set up celery with Django from the tuts but I keep getting 我正在尝试从tut和Django一起建立芹菜,但我一直

ModuleNotFoundError: No module named 'celery'

I have a main project called Tasklist with the structure: 我有一个名为Tasklist的主项目,其结构如下:

- Tasklist/
  - manage.py
  - Tasklist/
    - __init__.py
    - settings.py
    - celery.py
    - urls.py

My init .py is as follows: 我的init .py如下:

from __future__ import absolute_import, unicode_literals

from .celery import app as celery_app

__all__ = ['celery_app']

And my celery.py is like so: 我的celery.py就像这样:

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

app = Celery('')

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

I'm not sure if I need to alter the settings.py - but I'm running in a local environment so I shouldn't need to start a celery worker? 我不确定是否需要更改settings.py-但是我在本地环境中运行,所以我不需要启动芹菜工人吗? I'm pretty confused! 我很困惑!

I read that django-celery is redundant now the latest version of celery is here, so I only have celery 4.1.1 installed. 我读到django-celery是多余的,现在最新版本的celery在这里,所以我只安装了celery 4.1.1。

Steps: 脚步:

  1. If celery installed on virtualEnv , Activate VirtualEnv 如果celery安装在virtualEnv上,请激活VirtualEnv
  2. Navigate to path : /path/to/Tasklist/ (to app name level) 导航到路径: /path/to/Tasklist/ (到应用程序名称级别)
  3. Run celery -A Tasklist worker -l info 运行celery -A Tasklist worker -l info

-A for App Name. -A为应用程序名称。

Celery Setup and Installation : Official Document Celery设置和安装: 官方文档

In Settings.py Below setting can be managed. 在Settings.py以下可以管理设置。

BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM