【问题标题】:Django + Heroku celery module not found找不到 Django + Heroku 芹菜模块
【发布时间】:2018-08-20 00:01:46
【问题描述】:

我正在尝试将我的最新版本的 web 应用程序实时推送到 Heroku。我很乐意推向 Heroku,但这似乎并不正确。出于某种原因,我觉得 Heroku 正在跳过我的 requirements.txt。以防我在 Heroku 应用上手动安装 celery。

我遇到了与 celery 相关的特定问题,但如果 Heroku 跳过了我的 requirements.txt,这可能是一个更大的问题。

1.如果我跑步:

heroku run pip install celery

这让我一遍又一遍地安装包,它不应该踢回“要求已经满足”的错误吗?

2. 当我尝试推送到 heroku 时,我不断得到一个

File "/app/config/_celery.py", line 4, in <module>
from celery import Celery
ModuleNotFoundError: No module named 'celery'

对于我的生活,我无法弄清楚为什么,我已经卸载了 celery,在本地重新安装了它。它在我的 requirements.txt 上(Heroku 应该在推送到远程时安装它)。 celery 似乎在本地也能正常工作。

我将包含我认为必要的内容,但如果我遗漏了可能提供答案的内容,请告诉我。

这是我的项目文件结构:

POTRTMS(overall project folder)
|
+-config(holds settings)
|  |
|  +--settings
|  |  |
|  |  __init__.py
|  |  production.py
|  |  local.py
|  |  base.py
|  |
|  _celery.py
|  __init__.py (this is the __init__.py i'm referencing below)

_celery.py

from __future__ import absolute_import, unicode_literals
import sys
import os
from celery import Celery
from celery.schedules import crontab

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.production')

app = Celery('POTRTMS')
# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()

@app.task(bind=True)
def debug_task(self):
  print('Request: {0!r}'.format(self.request))


app.conf.beat_schedule = {
    'insurance_date': {
        'task': 'insurance_date',
        'schedule': crontab(minute=0, hour=8),

    },
}

__init.py__

from __future__ import absolute_import

from ._celery import app as celery_app

【问题讨论】:

    标签: django heroku celery django-celery


    【解决方案1】:

    我能够找出问题所在。在我的项目根文件夹中,我有 Pipfile 和 Pipfile.lock,这听起来像是一种处理 requirements.txt 的新方法。

    我不确定这些文件是如何进入我的项目的,但在删除它们后一切正常。

    【讨论】:

      猜你喜欢
      • 2016-04-18
      • 1970-01-01
      • 2019-02-18
      • 2014-01-08
      • 2015-09-21
      • 1970-01-01
      • 2021-04-12
      • 1970-01-01
      相关资源
      最近更新 更多