26

I was stuck with the process when I wanted to deploy django project on server today. When I run python manage.py runserver on server, the terminal shows me this:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 343, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 177, in fetch_command
    commands = get_commands()
  File "/usr/lib/python2.7/site-packages/django/utils/lru_cache.py", line 101, in wrapper
    result = user_function(*args, **kwds)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 72, in get_commands
    for app_config in reversed(list(apps.get_app_configs())):
  File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
    self.check_apps_ready()
  File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

The django version on the server is 1.8.5, and the local is 1.8.1. I doubt the version may cause this problem. But I also doubted the wsgi.py wasn't written properly, here's the wsgi.py:

import os
import sys

path = '/Users/Peterhon/Desktop/dict/'
if path not in sys.path:
    sys.path.append(path)

os.chdir(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dict.settings")

import django
django.setup()

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Here's the manage.py file:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dict.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.arg)

When I run python manage.py check on server, the output is below:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dict.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

Could anyone give me some tips? Thanks too much

idleberg
  • 11,699
  • 7
  • 41
  • 60
Peter Tsung
  • 835
  • 2
  • 9
  • 20

6 Answers6

21

This could well be an issue with your Django settings. For example, I just had specified in LOGGING a filename in a non-existent directory. As soon as I changed it to an existing directory, the issue was resolved.

jbasko
  • 6,698
  • 1
  • 36
  • 48
  • 8
    Had a problem with mysql and when ran `python manage.py check` got Library not loaded: /usr/local/lib/libmysqlclient.18.dylib but `python manage.py runserver` gives the Apps not loaded error so it looks like any issues with settings or configuration could give this error. – PhoebeB Jan 06 '16 at 12:43
12

I ran into this issue today. There was an app in INSTALLED_APPS that didn't exist. Once it was removed, it resolved the exception. Apps that can't be imported for any reason will also raise an AppRegistryNotReady exception.

Here's the bug history for this issue.

Additionally, trying to import something from the app level into the project level can cause this issue, too. For example, I'm currently working on project using Celery Beat. I tried defining task schedules at the app level as dictionaries which were then imported to the celery.py file of the project. Importing the dictionary from the app into the project caused Django to throw an AppRegistryNotReady exception. Likewise, importing items between apps can cause the exception.

infosmith
  • 594
  • 6
  • 13
5

./manage.py runserver will use your wsgi.py however it looks like the stack trace you've shown at the top does not include the wsgi file. Therefore the error is occurring before the wsgi file is loaded.

I'm not able to recreate your error, but since you seem to be using the new style wsgi and as you mention "the django version on the server is 1.8.5, and the local is 1.8.1", I'm wondering if there might be something wrong in your environment.

My suggested steps are:

  1. Rebuild your virtualenv. Delete the env folder and install again with pip install -r requirements.txt or similar.
  2. Check out other questions on StackOverflow - this seems to be a common issue. E.g as above: Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet

Hopefully someone with more experience will be able to add suggestions. Sorry I don't have the definitive answer for you.

Community
  • 1
  • 1
jamesc
  • 5,002
  • 3
  • 29
  • 42
  • `raise AppRegistryNotReady("Apps aren't loaded yet.")` it clearly sound like an other error than models not loaded yet… – christophe31 Dec 02 '15 at 08:15
0

There can be issue in your settings.py file . Specifically INSTALLED_APPS verify if you correctly included apps and separated with "," .

Waykos
  • 29
  • 2
0

I fixed it by setting the owner of the wsgi entry point that the apache calls to root:root

tstoev
  • 1,320
  • 9
  • 12
-1

I got this error too regardless of the existing answers. I solve by do locally import in the celery function.

Eric Aya
  • 69,000
  • 34
  • 174
  • 243
joe
  • 6,838
  • 12
  • 49
  • 93