import error in celery

后端 未结 3 1909
迷失自我
迷失自我 2021-02-07 03:45

this is the code which i am running:

from __future__ import absolute_import
from celery import Celery
celery1 = Celery(\'celery\',broker=\'amqp://\',backend=\'am         


        
3条回答
  •  走了就别回头了
    2021-02-07 04:10

    I had this issue together with pycharm and unittests, and want to add an additional answer. I have tested it with python 3 but assume the same happens if you use from __future__ import absolute_import with earlier versions.

    The root cause is described in the pycharm bug report https://youtrack.jetbrains.com/issue/PY-15889

    Summary: If you run unittests in pycharm, it always adds the folder containing the test script to the beginning of sys.path. If your celery.py is in the same path, python will try to load it first.

    Instead of changing file names I have resolved this by removing this folder from sys.path before importing celery.py in my ..._Test.py test scripts.

    # If running in pycharm, pycharm always adds the current path to the beginning (!) of sys.path
    # I have not found a setting to fix this - so I just remove the path again
    # This block can be removed once https://youtrack.jetbrains.com/issue/PY-15889 if fixed
    import sys
    import os
    sys.path.remove(os.path.dirname(__file__)) 
    
    import celery
    

提交回复
热议问题