2017-08-13 46 views
1

我一直在尋找答案。我在Ubuntu 16.04(數字海洋)上爲我的Django網站設置了一臺服務器,我的Django站點需要使用芹菜來完成一些週期性任務。Django celery ImportError:使用gunicorn綁定時沒有模塊命名芹菜?

它適用於我的開發環境。並運行python manage.py celery beatpython manage.py celery worker工作得很好。它全部安裝在virtualenv中。

這裏是我的文件:

# __init__.py

from __future__ import absolute_import 
from .celery_tasks import app as celery_app # noqa 

# celery_tasks.py

from __future__ import absolute_import 

import os 
from celery import Celery 

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

from django.conf import settings # noqa 

app = Celery('myproject') 

app.config_from_object('django.conf:settings') 
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) 


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

這是已經發生的錯誤:

# gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application

File "/root/myproject/myproject/__init__.py", line 2, in <module> 
from .celery_tasks import app as celery_app # noqa 
File "/root/myproject/myproject/celery_tasks.py", line 4, in <module> 
from celery import Celery 
ImportError: No module named celery 
[2017-08-13 07:29:36 +0000] [5463] [INFO] Worker exiting (pid: 5463) 
[2017-08-13 07:29:36 +0000] [5458] [INFO] Shutting down: Master 
[2017-08-13 07:29:36 +0000] [5458] [INFO] Reason: Worker failed to boot. 

還有一些似乎不相關的回溯。

請任何幫助非常感謝。我想我錯過了一些簡單的東西,但我一直在掙扎幾個小時。

回答

2

錯誤表示不是創建芹菜。 因此,將芹菜放入您的requirements.txt文件中,並在部署時安裝芹菜。 或者在您的服務器做:

pip install celery 

pip install -r requirements.txt 
相關問題