title: Django and Celery - ModuleNotFoundError: No module named 'celery.task'
body: <p>I wanted to start a periodic task in <code>Django</code> using <code>Celery</code>. Here are the relevant parts of my project:</p>
  <pre><code># celery.py
  
  from celery import Celery
  
  # set the default Django settings module for the 'celery' program.
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bookProjectSetting.settings')
  
  app = Celery('bookProjectSetting')
  
  # Using a string here means the worker doesn'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(f'Request: {self.request!r}')
  </code></pre>
  <p>The <code>__init__.py</code> looks like this:</p>
  <pre><code># 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
  
  __all__ = ('celery_app',)
  </code></pre>
  <p>My <code>tasks.py</code> file in my <code>books</code> app folder looks like this:</p>
  <pre><code>from books.models import Book
  from celery.schedules import crontab
  from celery.decorators import periodic_task
  
  @periodic_task(
      run_every=(crontab(minute='*/10')), 
      name=&quot;update_life_time_of_books&quot;, 
      ignore_result=True)
  def update_life_time_of_books():
     # do sth. 
  </code></pre>
  <p>I also set up <code>redis</code> as broker and installed the <code>django-celery-beat</code> stuff. But when I run the worker via the command:</p>
  <pre><code>celery -A bookProjectSetting beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
  </code></pre>
  <p>Then I get the following error:</p>
  <pre><code>File &quot;/home/ac3l1k/Desktop/PROJECT/simpleDjangoProjects/bookProject/env/lib/python3.8/site-packages/celery/local.py&quot;, line 403, in _compat_periodic_task_decorator
      from celery.task import periodic_task
  ModuleNotFoundError: No module named 'celery.task'
  </code></pre>
  <p>From the error I assume that something is wrong with the decorator but I can not tell why. Hope someone can help.</p>
  <p>Thnks in advance :=)</p>
  <p>NOTE: Here is the content of my <code>requirements.txt</code> file for version references</p>
  <p><code>$ pip freeze</code></p>
  <pre><code>amqp==5.0.1
  asgiref==3.2.10
  billiard==3.6.3.0
  celery==5.0.1
  click==7.1.2
  click-didyoumean==0.0.3
  click-repl==0.1.6
  Django==3.1.2
  django-celery-beat==2.1.0
  django-timezone-field==4.0
  djangorestframework==3.12.1
  kombu==5.0.2
  prompt-toolkit==3.0.8
  python-crontab==2.5.1
  python-dateutil==2.8.1
  pytz==2020.1
  redis==3.5.3
  six==1.15.0
  sqlparse==0.4.1
  vine==5.0.0
  wcwidth==0.2.5
  </code></pre>