Django Crontab keeps add "No module named 'django.utils.importlib'"

92 Views Asked by At

Every time I try to run python manage.py crontab add or run my testing script I get this:

python manage.py crontab add
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/trademaj/virtualenv/public_html/city/3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/trademaj/virtualenv/public_html/city/3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/trademaj/virtualenv/public_html/city/3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 257, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/trademaj/virtualenv/public_html/city/3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 39, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/opt/alt/python38/lib64/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 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/trademaj/virtualenv/public_html/city/3.8/lib/python3.8/site-packages/django_crontab/management/commands/crontab.py", line 4, in <module>
    from django_crontab.crontab import Crontab
  File "/home/trademaj/virtualenv/public_html/city/3.8/lib/python3.8/site-packages/django_crontab/crontab.py", line 13, in <module>
    from django.utils.importlib import import_module
ModuleNotFoundError: No module named 'django.utils.importlib'

Settings:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'nema_app',
    'user_auth',
    'rest_framework',
    'rest_framework.authtoken',
    'django_crontab',
]
.
.
.
.
.
CRONJOBS = [
    ('*/2 * * * *', 'nema_app.job.my_function')
]

job.py:

from user_auth.models import UserIntervalInfo

def my_function():
    # Your code here
    interval = UserIntervalInfo.objects.all()[0]
    interval.interval = interval.interval + 1
    interval.save() 
    print("My function")

Banging my head here cause I've reinstall django-crontab and followed the instructions multiple times.

0

There are 0 best solutions below