0

I am converting a Django website from Python 2 to Python 3. To do this, I ran 2to3 on the whole project. Now, upon running the server (which works fine in Python 2). Now, there appears to be an error django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. that seems to originate with an issue loading the django_comments app. It is not clear to me whether this is related to a templates/models issue or something else. Python3 was installed in the virtual environment for this project.

(env) user:project user$ python3 manage.py check
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File ".../src/project/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File ".../src/project/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File ".../src/project/env/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File ".../src/project/env/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File ".../src/project/env/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File ".../src/project/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File ".../src/project/language/__init__.py", line 3, in <module>
    from django_comments.models import Comment
  File ".../src/project/env/lib/python3.7/site-packages/django_comments/models.py", line 7, in <module>
    from .abstracts import (
  File ".../src/project/env/lib/python3.7/site-packages/django_comments/abstracts.py", line 4, in <module>
    from django.contrib.contenttypes.fields import GenericForeignKey
  File ".../src/project/env/lib/python3.7/site-packages/django/contrib/contenttypes/fields.py", line 3, in <module>
    from django.contrib.contenttypes.models import ContentType
  File ".../src/project/env/lib/python3.7/site-packages/django/contrib/contenttypes/models.py", line 133, in <module>
    class ContentType(models.Model):
  File ".../src/project/env/lib/python3.7/site-packages/django/db/models/base.py", line 103, in __new__
    app_config = apps.get_containing_app_config(module)
  File ".../src/project/env/lib/python3.7/site-packages/django/apps/registry.py", line 252, in get_containing_app_config
    self.check_apps_ready()
  File ".../src/project/env/lib/python3.7/site-packages/django/apps/registry.py", line 135, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

I have also ensured that DJANGO_SETTINGS_MODULE is configured in manage.py.

  1 #!/usr/bin/env python3
  2
  3 import os
  4 import sys
  5
  6 if __name__ == "__main__":
  7     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
  8
  9     from django.core.management import execute_from_command_line
 10
 11     execute_from_command_line(sys.argv)
woefipuasd
  • 23
  • 4

2 Answers2

0

maybe you can do like this in manage.py:

import os
import django
import sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mis.settings")
django.setup()

from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Ginta
  • 151
  • 6
  • Thank you but no luck. The same error is thrown except the traceback starts at django.setup() as below: `Traceback (most recent call last): File "manage.py", line 9, in django.setup() File "~/src/app/env/lib/python3.7/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) ...` – woefipuasd Oct 29 '19 at 03:14
0

I just found an answer pythonanywhere, it means that you shouldn't need to call django.setup().In addition, you can try to disable your apps in INSTALLED_APPS one by one so that can identify where the problems from.Don't forget to restore the code in manage.py at first!

Ginta
  • 151
  • 6
  • Thank you. This is what I am trying now. By 'restore the code in manage.py' I presume you mean revert any changes I made (such as adding django.setup()? – woefipuasd Oct 29 '19 at 19:32