我正在尝试将 Celery 与 Redis 一起使用。
这是我的celery.py文件:
from __future__ import absolute_import
from celery import Celery
celery=Celery(include=[ 'tasks.chatterbox' ])
# import celery config file
celery.config_from_object('celeryconfig')
if __name__ == '__main__':
celery.start()
这是我的celeryconfig.py文件:
BROKER_URL = 'redis://localhost:6379/0'
# redis backend
CELERY_RESULT_BACKEND = 'redis://'
当我运行时:
celery -A broker.celery worker -l info
我收到了这个错误:
Traceback (most recent call last):
File "/usr/local/bin/celery", line 9, in <module>
load_entry_point('celery==3.1.11', 'console_scripts', 'celery')()
File "/usr/local/lib/python2.7/dist-packages/celery-3.1.11-py2.7.egg/celery/__main__.py", line 30, in main
main()
File "/usr/local/lib/python2.7/dist-packages/celery-3.1.11-py2.7.egg/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/usr/local/lib/python2.7/dist-packages/celery-3.1.11-py2.7.egg/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-3.1.11-py2.7.egg/celery/bin/base.py", line 306, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/usr/local/lib/python2.7/dist-packages/celery-3.1.11-py2.7.egg/celery/bin/celery.py", line 761, in handle_argv
return self.execute(command, argv)
File "/usr/local/lib/python2.7/dist-packages/celery-3.1.11-py2.7.egg/celery/bin/celery.py", line 693, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/usr/local/lib/python2.7/dist-packages/celery-3.1.11-py2.7.egg/celery/bin/worker.py", line 179, in run_from_argv
return self(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/celery-3.1.11-py2.7.egg/celery/bin/base.py", line 269, in __call__
ret = self.run(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery-3.1.11-py2.7.egg/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-3.1.11-py2.7.egg/celery/worker/__init__.py", line 100, in __init__
self.setup_instance(**self.prepare_args(**kwargs))
File "/usr/local/lib/python2.7/dist-packages/celery-3.1.11-py2.7.egg/celery/worker/__init__.py", line 126, in setup_instance
self.should_use_eventloop() if use_eventloop is None
File "/usr/local/lib/python2.7/dist-packages/celery-3.1.11-py2.7.egg/celery/worker/__init__.py", line 245, in should_use_eventloop
self._conninfo.is_evented and not self.app.IS_WINDOWS)
File "/usr/local/lib/python2.7/dist-packages/kombu-3.0.16-py2.7.egg/kombu/connection.py", line 836, in is_evented
return self.transport.supports_ev
File "/usr/local/lib/python2.7/dist-packages/kombu-3.0.16-py2.7.egg/kombu/connection.py", line 786, in transport
self._transport = self.create_transport()
File "/usr/local/lib/python2.7/dist-packages/kombu-3.0.16-py2.7.egg/kombu/connection.py", line 518, in create_transport
return self.get_transport_cls()(client=self)
File "/usr/local/lib/python2.7/dist-packages/kombu-3.0.16-py2.7.egg/kombu/transport/redis.py", line 916, in __init__
self.connection_errors, self.channel_errors = self._get_errors()
File "/usr/local/lib/python2.7/dist-packages/kombu-3.0.16-py2.7.egg/kombu/transport/redis.py", line 954, in _get_errors
return get_redis_error_classes()
File "/usr/local/lib/python2.7/dist-packages/kombu-3.0.16-py2.7.egg/kombu/transport/redis.py", line 78, in get_redis_error_classes
from redis import exceptions
ImportError: No module named redis
最后是我的项目结构:
.
├── __init__.py
├── celeryconfig.py
├── broker
│ ├── celery.py
│ ├── __init__.py
├── tasks
├── chatterbox.py
├── __init__.py
我在用:
- 芹菜 3.1.11
- Redis 2.8.8