【问题标题】:Celery Elastic Beanstalk ImportError: cannot import name CeleryCelery Elastic Beanstalk ImportError: cannot import name Celery
【发布时间】:2016-01-09 04:37:22
【问题描述】:

我正在尝试通过 Django 让 celery 在 Elastic Beanstalk 上工作,但运气不佳。

我可以在我的本地机器上使用 celery,但是每当我部署到 Elastic Beanstalk 时,它都不喜欢这行:from celery import Celery。

我查看了其他一些关于此的问题,他们说将我的 celery.py python 文件的名称更改为 celeryapp.py 之类的名称,但这不会改变结果。

完整的错误信息是这样的:

  File "manage.py", line 10, in <module>
  execute_from_command_line(sys.argv)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
  utility.execute()
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute
  settings.INSTALLED_APPS
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
  self._setup(name)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
  self._wrapped = Settings(settings_module)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
  mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
  __import__(name)
  File "/opt/python/bundle/3/app/MY_PROJECT/__init__.py", line 5, in <module>
  from .celery import app as celery_app
  File "/opt/python/bundle/3/app/MY_PROJECT/celery.py", line 5, in <module>
  from celery import Celery
  File "/opt/python/current/app/MY_PROJECT/celery.py", line 5, in <module>
  from celery import Celery
  ImportError: cannot import name Celery
   (ElasticBeanstalk::ExternalInvocationError)

有人知道为什么 celery 不能导入 Celery 吗?在我的 requirements.txt 中,我有 celery==3.1.18,所以我假设该库已安装。

【问题讨论】:

    标签: python django amazon-web-services celery amazon-elastic-beanstalk


    【解决方案1】:

    requirements.txt 中也需要 django-celery。

    更新: 我们也在部署后重新启动 celery 服务。

    commands:
        90_create_post_dir:
            command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
            ignoreErrors: true
    
    files:
        "/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh":
            mode: "000755"
            owner: root
            group: users
            content: |
                #!/usr/bin/env bash
                service celeryd restart
    

    您显然需要设置 celery 以作为守护程序运行,以及整个过程。

    【讨论】:

    • 这就是答案。在从您的虚拟环境中部署之前,请务必运行 pip freeze > requirements.txt(如果您正在使用)。
    • @DeusExMachina25 这是不正确的。我在 requirements.txt 中有 django-celery,仍然出现此错误。
    • 这是其中的一部分。你需要安装和工作芹菜,这本身就很棘手。但这并不是问题的真正含义。
    • 为什么需要django-celery?我已经将 Django 与 Celery 一起使用,但从不需要它。它的page on pypi 说“不再需要这个项目”(强调原文)。
    • 哇哦,那变了!我们不再使用那个项目了。 AWS 有自己的队列系统,这更有意义。我们现在重新设计和使用 AWS Lambda,不需要队列。
    猜你喜欢
    • 2020-04-20
    • 2020-10-10
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    • 2016-05-16
    • 2018-10-27
    • 2020-07-16
    • 2019-06-10
    相关资源
    最近更新 更多