以项目名称作为命令行参数启动芹菜会发出错误

时间:2016-10-30 16:29:42

标签: python django celery eventlet

我在dev VM&ubuntu / trusty'下有一个项目。 我将 virtualenv 与以下软件包一起使用:

celery 3.1.23
eventlet 0.18.4
django 1.8.15

Python版本是3.4.3。

当我以这种方式开始一个芹菜工人时:

celery worker --loglevel=INFO -P eventlet -c 3 -Q default -E -n default.queue -l INFO

它正确启动,但所有任务都保留在' 待处理'状态。

当我以这种方式启动时(在' -A' 参数中使用项目名称):

celery worker -A meridian --loglevel=INFO -P eventlet -c 3 -Q default -E -n default.queue -l INFO

它发出错误:

(meridian)vagrant@vagrant-ubuntu-trusty-64:/vagrant/meridian/meridian$ celery worker -A meridian --loglevel=INFO -P eventlet -c 3 -Q default -E -n default.queue -l INFO
Traceback (most recent call last):
  File "/home/vagrant/.virtualenvs/meridian/lib/python3.4/site-packages/celery/app/utils.py", line 241, in find_app
    found = sym.app
AttributeError: 'module' object has no attribute 'app'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vagrant/.virtualenvs/meridian/bin/celery", line 11, in <module>
    sys.exit(main())
  File "/home/vagrant/.virtualenvs/meridian/lib/python3.4/site-packages/celery/__main__.py", line 30, in main
    main()
  File "/home/vagrant/.virtualenvs/meridian/lib/python3.4/site-packages/celery/bin/celery.py", line 81, in main
    cmd.execute_from_commandline(argv)
  File "/home/vagrant/.virtualenvs/meridian/lib/python3.4/site-packages/celery/bin/celery.py", line 793, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/home/vagrant/.virtualenvs/meridian/lib/python3.4/site-packages/celery/bin/base.py", line 309, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/home/vagrant/.virtualenvs/meridian/lib/python3.4/site-packages/celery/bin/base.py", line 469, in setup_app_from_commandline
    self.app = self.find_app(app)
  File "/home/vagrant/.virtualenvs/meridian/lib/python3.4/site-packages/celery/bin/base.py", line 489, in find_app
    return find_app(app, symbol_by_name=self.symbol_by_name)
  File "/home/vagrant/.virtualenvs/meridian/lib/python3.4/site-packages/celery/app/utils.py", line 246, in find_app
    found = sym.celery
AttributeError: 'module' object has no attribute 'celery'

有人知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

您的项目(应用程序)似乎无法导入。

您的选择:

  • 创建一个合适的Python包(setup.py),并使用pip install /project/directory进行安装。这将在virtualenv/lib/python-version/site-packages/中创建文件的 copy 。通过这本书,但很少使用的方法。
  • pip install -e /project/directory还需要setup.py,将项目符号链接到site-packages,因此它是每个virtualenv的一次性操作。广泛用于包开发人员。
  • 在导入项目之前,请在Python代码中处理sys.path。例: import sys sys.path.append('/project/directory')
  • 通过PYTHONPATH环境变量处理导入目录。通常的平台相关PATH规则适用(条目由:分隔,但Windows上为;。这种方式非常适合部署。 shell中的示例: export PYTHONPATH=/project/directory exec /virtualenv/bin/celery worker ...

答案 1 :(得分:0)

我在这里找到了解决方案:

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

我唯一需要做的就是将一个文件 celery.py 添加到项目的根目录中,然后添加几行到 init.py 放在同一目录中。请参阅上面的文档。