Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.7K
Views
Django y Celery - ModuleNotFoundError: ningún módulo llamado 'celery.task'

Quería comenzar una tarea periódica en Django usando Celery . Aquí están las partes relevantes de mi proyecto:

 # celery.py from celery import Celery # set the default Django settings module for the 'celery' program. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bookProjectSetting.settings') app = Celery('bookProjectSetting') # Using a string here means the worker doesn't have to serialize # the configuration object to child processes. # - namespace='CELERY' means all celery-related configuration keys # should have a `CELERY_` prefix. app.config_from_object('django.conf:settings', namespace='CELERY') # Load task modules from all registered Django app configs. app.autodiscover_tasks() @app.task(bind=True) def debug_task(self): print(f'Request: {self.request!r}')

El __init__.py se ve así:

 # 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 __all__ = ('celery_app',)

Mi archivo tasks.py en la carpeta de la aplicación de mis books se ve así:

 from books.models import Book from celery.schedules import crontab from celery.decorators import periodic_task @periodic_task( run_every=(crontab(minute='*/10')), name="update_life_time_of_books", ignore_result=True) def update_life_time_of_books(): # do sth.

También configuré redis como intermediario e instalé el material django-celery-beat . Pero cuando ejecuto el trabajador a través del comando:

 celery -A bookProjectSetting beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler

Entonces me sale el siguiente error:

 File "/home/ac3l1k/Desktop/PROJECT/simpleDjangoProjects/bookProject/env/lib/python3.8/site-packages/celery/local.py", line 403, in _compat_periodic_task_decorator from celery.task import periodic_task ModuleNotFoundError: No module named 'celery.task'

Por el error asumo que algo anda mal con el decorador pero no puedo decir por qué. Espero que alguien pueda ayudar.

Gracias de antemano :=)

NOTA: Aquí está el contenido de mi archivo requirements.txt para referencias de versiones

$ pip freeze

 amqp==5.0.1 asgiref==3.2.10 billiard==3.6.3.0 celery==5.0.1 click==7.1.2 click-didyoumean==0.0.3 click-repl==0.1.6 Django==3.1.2 django-celery-beat==2.1.0 django-timezone-field==4.0 djangorestframework==3.12.1 kombu==5.0.2 prompt-toolkit==3.0.8 python-crontab==2.5.1 python-dateutil==2.8.1 pytz==2020.1 redis==3.5.3 six==1.15.0 sqlparse==0.4.1 vine==5.0.0 wcwidth==0.2.5
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

La "tarea" ya no está en la versión 5.x Puede usar la versión 4.x

  • pip3 desinstalar apio
  • pip3 instalar apio == 4.4.2

Edito los espacios

over 4 years ago · Santiago Trujillo Report

0

Rechazaron esa funcionalidad como entendí de este problema: https://github.com/celery/celery/issues/6406

Ahora parece ser que necesita usar esto para realizar tareas programadas:

https://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html?highlight=periodic

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!