0
我想與redis的django一起使用芹菜作爲經紀人。我的應用程序名稱之一是用戶,其模型是由其他應用程序導入的。當我運行django服務器時,它啓動時沒有任何錯誤,一切正常。芹菜工人不啓動一個應用程序的ImportError
但是,當我嘗試啓動命令「芹菜-A項目工人-l INFO」芹菜工作者,我得到以下錯誤:
Traceback (most recent call last):
File "/usr/local/bin/celery", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 30, in main
main()
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 793, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 311, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 785, in handle_argv
return self.execute(command, argv)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 717, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/usr/local/lib/python2.7/dist-packages/celery/bin/worker.py", line 179, in run_from_argv
return self(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 274, in __call__
ret = self.run(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/worker.py", line 212, in run
state_db=self.node_format(state_db, hostname), **kwargs
File "/usr/local/lib/python2.7/dist-packages/celery/worker/__init__.py", line 95, in __init__
self.app.loader.init_worker()
File "/usr/local/lib/python2.7/dist-packages/celery/loaders/base.py", line 128, in init_worker
self.import_default_modules()
File "/usr/local/lib/python2.7/dist-packages/celery/loaders/base.py", line 116, in import_default_modules
signals.import_modules.send(sender=self.app)
File "/usr/local/lib/python2.7/dist-packages/celery/utils/dispatch/signal.py", line 166, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/local/lib/python2.7/dist-packages/celery/fixups/django.py", line 73, in on_import_modules
self.worker_fixup.validate_models()
File "/usr/local/lib/python2.7/dist-packages/celery/fixups/django.py", line 158, in validate_models
django_setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/path_to_project/project/app1/models.py", line 2, in <module>
from app1.models import *
File "/path_to_project/project/project/models.py", line 9, in <module>
from user.models import *
ImportError: No module named models
這裏要注意的事情是,它說沒有模塊名爲模型和不是沒有模塊名爲user.models。這可能意味着與其他文件存在一些衝突,儘管我已經進行了雙重檢查,並且項目目錄或app1目錄中沒有user.py。如果我將應用程序「user」重命名爲「user2」,則工作人員啓動。另外值得注意的是芹菜在某個時候開始很好的事實。從那時起,代碼已經改變,但沒有添加應用程序。
我的項目具有以下結構(只顯示相關部分)
- project
- project
- celery.py
- models.py
- user
- models.py
- app1
- models.py
- tasks.py
和celery.py是
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
app = Celery('project')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
芹菜配置是
BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
感謝
是否有重新命名它的解決方法。我嘗試絕對導入與project.user,但它說沒有模塊名稱project.user –
你可能必須使用'python 3'爲您的項目或可以做這樣的事情[這個答案](http://stackoverflow.com/ a/11158224)能夠使用'project.user'。或者只是重命名'用戶',即使是大寫也可以解決它。 –