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:
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']
–
–
–
–
"SARyS",
broker='pyamqp://guest:guest@rabbitmq.insertmendoza.com.ar',
include=["SARyS.Apps.TaskManager.Tasks"]
–
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.