[Python] ImportError: cannot import name 'Celery' from 'celery'

Discussão em 'Python' iniciado por Stack, Abril 18, 2025.

  1. Stack

    Stack Membro Participativo

    ImportError: cannot import name 'Celery' from 'celery'

    The code is running fine in my local machine. when i run this code on azure server then create this issue.

    I also renamed celery.py file to celeryy.py file and then checked the error is still same.

    here below is my project file structure in below screenshot.

    [​IMG]

    __init__.py file:

    from __future__ import absolute_import
    from core.celery import app as celery_app

    __all__ = ['celery_app']


    celery.py file:

    from __future__ import absolute_import
    import os
    from celery import Celery

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')

    app = Celery('core')
    app.config_from_object('django.conf:settings', namespace='CELERY')
    app.autodiscover_tasks()

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


    task.py file:

    from celery import shared_task
    from time import sleep
    from azure.datalake.store import core, lib, multithread
    from django.core.mail import send_mail
    token = lib.auth()
    adls_client = core.AzureDLFileSystem(token, store_name='bnlweda04d3232gsdfs')

    @shared_task
    def sleepy(duration):
    sleep(duration)
    return None

    @shared_task
    def send_email_task(subject,message,from_email,recipient_email,fail_silently):
    sleep(30)
    send_mail(
    subject,message,from_email,recipient_email,fail_silently
    )
    return 'Mail sent success'



    I'm using celery version: 4.4.0 and python version: 3.8.10

    Continue reading...

Compartilhe esta Página