Traceback (most recent call last):
File "./fb_archive/__init__.py", line 5, in <module>
from .celery import app as celery_app
File "./fb_archive/celery.py", line 5, in <module>
from celery import Celery
ImportError: No module named 'celery'
unable to load app 0 (mountpoint='') (callable not found or import error)
uWGSI说No module name celery
。
没有uWGSI,它运行良好。
我使用python 3.5和virtualenv。
我用python 2.7和uWGSI测试,它可以加载芹菜。 如何用python 3.x加载芹菜?
这是我的celery.py。
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fb_archive.settings')
app = Celery('fb_archive')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
app.conf.update(
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
)
app.conf.update(
CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend',
)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
这是我的 init .py。
from __future__ import absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
答案 0 :(得分:1)
您可能已经为Python2.7安装了芹菜,但没有为Python3安装芹菜。您可以尝试使用pip3 install celery
为Python3安装它。
您可能做在正常环境中为Python3安装了芹菜,但它没有安装在您的virtualenv中。
答案 1 :(得分:0)
将uwsgi用于python3.X
如果你想用uwsgi在python3.X(virtualenv)中运行django,那么uwsgi必须安装在python3.X virtualenv中,我猜你运行的是没有virtualenv的python2.7 uwsgi。你需要删除你的uwsgi安装,然后在你的virtualenv for python3.X中重新安装uwsgi,然后当你从virtualenv中运行uwsgi时它将包含celery。
请按照以下步骤操作:
sudo pip uninstall uwsgi
source venv/bin/activate
pip install uwsgi
uwsgi --ini /etc/uwsgi/sites/project.ini
sudo chown <user> /path/to/file
或只是执行sudo。