Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I try to include tasks in my webapplication but i can't start the celery work.

My project structure is the following:

website/website --> init.py, settings.py, urls.py, wsgi.py

website/index --> init.py, celery_app.py, tasks.py

Index is my startpage where i want to run the tasks.

index/celery_app.py has the following code:

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()

index/tasks.py:

from __future__ import  absolute_import
from .celery_app import app
@app.task
def test_func():
    print("Test Background Task")

When i want to start the worker with celery -A index worker --loglevel=info I get the following error: ModuleNotFoundError: No module named 'celery'. I run the commandprompt in the index folder.

The other solutions in similar questions didn't help me.

Screenshot of my Packages: Installed packages

There is a problem with your file structure. Your celery app should be on the same folder as settings.py

website/website --> init.py, settings.py, urls.py, wsgi.py, celery_app.py

website/index --> init.py, tasks.py

and also in the init.py in the website folder should be having

from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery_app import app as celery_app
__all__ = ['celery_app']
                Hey argo. That was the first thing i tried. I changed my structure and added the code but i have still the ModuleNotFoundError.
– Neal Mc Beal
                Aug 27, 2018 at 15:34
                Yeah my django app is working. I've added a screenshot of all my packages in the environment
– Neal Mc Beal
                Aug 27, 2018 at 15:41
                Also your CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672/' needs to be fixed. You are using without any userid password. That might also be the issue
– Arghya Saha
                Aug 27, 2018 at 15:44
                @NealMcBeal Could you type pip list | grep celery in the same terminal and see if you get celery mentioned?
– Arghya Saha
                Aug 27, 2018 at 15:46
    "SARyS",
    broker='pyamqp://guest:guest@rabbitmq.insertmendoza.com.ar',
    include=["SARyS.Apps.TaskManager.Tasks"]
                Hey Nelson, your answer would be more useful for the others if you added more information: why would you define the app this way? What does this code mean and why do you think it solves the OP's problem? Etc.
– natka_m
                Nov 25, 2020 at 23:00

I found the solution. The problem was the commandprompt. I couldn't use the "normal" commandprompt. Instead of the normal i opened the commandprompt of my conda environment and now it works.

For everyone who wants to know where you can find the prompt/termin:

Open Anaconda Navigator --> Environments -->Select your Environment --> Click on the Arrow --> Open Terminal and then navigate with cd (if you use windows) to the location you want.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.