3

I am working on a Django project, and need to run cron tasks periodically to go through and delete all outdated files. I tried this same method with django_extensions and crontab, but I keep getting this same error. Within settings.py, I have:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'Data_Science_Web_App',
    'django_celery_beat',
]

in my INSTALLED_APPS section. 'Data_Science_Web_App' is the name of my application. When I used pip3 install django_celery_beat, it worked fine. However, when I try to migrate changes, I get this message:

(djangoenv) Daeyongs-Air:Data_Science_Project daeyong$ python3 manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site- 
  packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site- 
  packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site- 
  packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)

  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site- 
  packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site- 
  packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File 
  "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", 
  line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
  ModuleNotFoundError: No module named 'django_celery_beat'

When I check using pip freeze, it is evident that django_celery_beat is there:

(djangoenv) Daeyongs-Air:Data_Science_Project daeyong$ pip freeze
amqp==5.0.2
asgiref==3.2.10
billiard==3.6.3.0
celery==5.0.5
certifi==2020.6.20
cffi==1.14.2
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
cycler==0.10.0
Django==3.1.4
django-braces==1.14.0
django-celery-beat==2.1.0
django-common-helpers==0.9.2
django-cron==0.5.1
django-crontab==0.7.1
django-debug-toolbar==2.2
django-timezone-field==4.1.1

... and the list goes on.

Can somebody please help me discover the issue behind this? Thank you!

DaeyongK
  • 71
  • 1
  • 3

5 Answers5

1

I also met this. Even though haven't solved this, I found it should be a version or package conflict. I tried but didn't find compatible versions of them(django celery celery-beat-beat, maybe etc.)

Then I discard the 'django_celery_beat' from the INSTALLED_APPS. Anyway, it works.

If you have a better solution, please tell us.

sevsea
  • 33
  • 6
1

For me the problem was with the python version: django_celery_beat was installed on python3.9 site-packages and pip was using python3.8 site-packages.

try:

python -m pip install django-celery-beat

and then:

INSTALLED_APPS = [
....,
'django_celery_beat',
]

then migrate:

python manage.py makemigrations
python manage.py migrate
Zakir Adel
  • 13
  • 4
0

django_celery_beat must be before Data_Science_Web_Appin INSTALLED_APPS

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_celery_beat',
    'Data_Science_Web_App',
]
jgmh
  • 639
  • 10
  • 22
0

For me a little pip install did it.

run this:

pip install django-celery-beat
MD Mushfirat Mohaimin
  • 1,966
  • 3
  • 10
  • 22
0

I had this problem too, but then I found that I didn't put a comma after I added "django_celery_beat" to INSTALLED_APPS

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/34784535) – miloserdow Aug 07 '23 at 22:03