Django, ImportError: cannot import name Celery, possible circular import?

前端 未结 10 716
情书的邮戳
情书的邮戳 2021-01-31 14:43

I went through this example here:

http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html

All my tasks are in files called tasks.py.

10条回答
  •  时光说笑
    2021-01-31 15:18

    For someone who want to know what cause this error:
    I have meet this problem just now, then I found the problem --- sys.path.
    Maybe you add some path to sys.path like me, I add below code in manage.py,

    ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    SRC_PATH = os.path.join(ROOT_PATH, 'src')
    CONF_PATH = os.path.join(ROOT_PATH, 'conf')
    
    sys.path.insert(0, SRC_PATH)
    sys.path.insert(0, CONF_PATH)
    

    so, from celery import Celery would search celery in SRC_PATH and CONF_PATH first, that's the problem.

    change to

    sys.path.append(SRC_PATH)
    sys.path.append(CONF_PATH)
    

    It would search in python's lib and site-packages first. Solved perfectly.

提交回复
热议问题