芹菜工人导入错误

时间:2014-06-11 07:57:32

标签: python celery

当我尝试开始我的芹菜工作时,我收到导入错误。

我已按照http://hairycode.org/2013/07/23/first-steps-with-celery-how-to-not-trip/

的所有步骤进行操作

我的项目布局是这样的:

project/
    project/celeryconfig.py
    project/framework/celery/celery.py
    project/framework/email/email_tasks.py

我的celeryconfig.py代码是:

# default RabbitMQ broker
BROKER_URL = 'amqp://'

# default RabbitMQ backend
CELERY_RESULT_BACKEND = 'amqp://'

celery.py代码就像:

from __future__ import absolute_import

from celery import Celery

celery = Celery(include = [

                           'framework.email.email_tasks'

                          ])
celery.config_from_object('celeryconfig')

if __name__ == '__main__':
    celery.start()

最后是email_tasks.py

from email.mime.text import MIMEText
from framework.celery.celery import celery

@celery.task
def send_email(to = None, subject = None, message = None):
    fro = "hairycode-noreply@hairycode.org"
    msg = MIMEText(message)
    msg['Subject'] = subject
    msg['From'] = fro
    msg['To'] = to

    s = smtplib.SMTP('mail.hairycode.org')
    s.ehlo()
    s.starttls()
    s.ehlo()
    s.login('noxevolution', 'demolish@1992')
    s.sendmail('hairycode-noreply@hairycode.org', [to], msg.as_string)
    s.quit()
    return True

导入错误就像我尝试启动worker时一样:

$ celery -A framework.celery.celery worker -l debug
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 769, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 304, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 464, in setup_app_from_commandline
    self.app = self.find_app(app)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 484, in find_app
    return find_app(app, symbol_by_name=self.symbol_by_name)
  File "/usr/local/lib/python2.7/dist-packages/celery/app/utils.py", line 223, in find_app
    sym = symbol_by_name(app, imp=imp)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 487, in symbol_by_name
    return symbol_by_name(name, imp=imp)
  File "/usr/local/lib/python2.7/dist-packages/kombu/utils/__init__.py", line 92, in symbol_by_name
    module = imp(module_name, package=package, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/celery/utils/imports.py", line 101, in import_from_cwd
    return imp(module, package=package)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named framework.celery

0 个答案:

没有答案