我在dev VM 'ubuntu/trust '下有一个项目。我在以下包中使用virtualenv:
celery 3.1.23
eventlet 0.18.4
django 1.8.15
Python版本为3.4.3。
当我以这种方式启动一个celery worker时:
celery worker --loglevel=INFO -P eventlet -c 3 -Q default -E -n default.queue -l INFO
正常启动,但所有任务停留在'pending'状态
当我以这种方式开始时(项目名称在'-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'
有谁知道怎么解决这个问题吗?
看来你的项目(应用程序)是不可导入的。
你的选择:
- 创建一个合适的Python包(setup.py),用
-
pip install -e /project/directory
还需要setup.py,将符号链接项目到站点包中,因此它是每个虚拟环境的一次操作。广泛用于包开发人员。 - 在导入项目之前,请注意Python代码中的
sys.path
。例子:import sys sys.path.append('/project/directory')
- 通过
PYTHONPATH
环境变量负责导入目录。通常依赖于平台的PATH
规则适用(在Windows上,除;
外,所有地方都用:
分隔条目)。这种方式在部署中非常流行。shell中的示例:export PYTHONPATH=/project/directory exec /virtualenv/bin/celery worker ...
pip install /project/directory
安装它。这将在virtualenv/lib/python-version/site-packages/
中创建copy文件。按规定,但很少使用的方法。我找到了一个解决方案:
http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html 我唯一需要做的就是在项目的根目录中添加一个文件celery.py,然后在同一目录中的init.py中添加几行。