Django celery ImportError: no module named celery when using gunicorn bind?

Viewed 2311

I have been searching everywhere for an answer to this. I am setting up a server for my Django website on Ubuntu 16.04 (digital ocean) and my Django site requires the use of celery for some periodic tasks.

It works in my development environment. And running python manage.py celery beat and python manage.py celery worker work just fine. It was all installed inside a virtualenv as well.

Here are my files:

# __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))

And this is the error that has been happening:

# 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.

There is also some more traceback which didn't seem as relevant.

Please, any help is MUCH appreciated. I think I'm missing something simple but I've been struggling with this for hours.

1 Answers
Related