I have read many similar posts with the same situation and tried a few things suggested if they were at all related. I just updated to Django 1.9 and I received this traceback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/django/www/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/opt/django/www/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/opt/django/www/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/opt/django/www/local/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/opt/django/www/local/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/opt/django/www/src/site_aggrigator/__init__.py", line 2, in <module>
import management
File "/opt/django/www/src/site_aggrigator/management/__init__.py", line 4, in <module>
from django.contrib.auth.models import Permission
File "/opt/django/www/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/opt/django/www/local/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/opt/django/www/local/lib/python2.7/site-packages/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "/opt/django/www/local/lib/python2.7/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "/opt/django/www/local/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.
All my apps are installed on my virtual env for sure because the app was running fine before I made the update. I also received this right before my update:
/opt/django/www/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/auth/models.py:41: RemovedInDjango19Warning: Model class django.contrib.auth.models.Permission doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Permission(models.Model):
And one post provided a solution of :
INSTALLED_APPS = (
"django.contrib.auth.models.Permission",
Which I also did as they said would be a viable solution. Anyone else had this issue?
Try to add this (after the declaration of SECRET_KEY):
import django
django.setup()
Related
I hit a problem when run django from command line with manage.py runserver.
The same code is fine with Django 1.5 several months ago.
Today I wanna pickup the code again and run upon Django 1.8.3 and python2.7.10 .
Now, got error here:
Traceback (most recent call last):
File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/media/wni/study/workspace4320151111/weichun/mytheme/models.py", line 8, in <module>
from mezzanine.pages.models import Page
File "/media/wni/study/workspace4320151111/weichun/mezzanine/pages/models.py", line 34, in <module>
class Page(BasePage):
File "/media/wni/study/workspace4320151111/weichun/mezzanine/core/models.py", line 350, in __new__
return super(OrderableBase, cls).__new__(cls, name, bases, attrs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 298, in __new__
new_class.add_to_class(field.name, copy.deepcopy(field))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "/media/wni/study/workspace4320151111/weichun/mezzanine/generic/fields.py", line 226, in contribute_to_class
super(KeywordsField, self).contribute_to_class(cls, name)
File "/media/wni/study/workspace4320151111/weichun/mezzanine/generic/fields.py", line 84, in contribute_to_class
cls._meta.get_fields_with_model()]:
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 56, in wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 432, in get_fields_with_model
return [self._map_model(f) for f in self.get_fields()]
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 740, in get_fields
return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 802, in _get_fields
all_fields = self._relation_tree
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 60, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 709, in _relation_tree
return self._populate_directed_relation_graph()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 681, in _populate_directed_relation_graph
all_models = self.apps.get_models(include_auto_created=True)
File "/usr/local/lib/python2.7/dist-packages/django/utils/lru_cache.py", line 101, in wrapper
result = user_function(*args, **kwds)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 168, in get_models
self.check_models_ready()
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
Anyone knows how to fix it?
Thanks.
Wesley
I think you need to change your wsgi.py file as you go for different version of Django.
import os
import sys
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'YourAppName.settings'
application = WSGIHandler()
And try to comment all third party application imported in settings.py.
1] ./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.
2] This could well be an issue with your Django settings. For example,may in LOGGING a filename in a non-existent directory.
3] or check this
When I'm typing python manage.py makemigrations I get
Traceback(most recent call last):
File "manage.py", line 10, in < module >
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 10 8, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name)
File "/var/www/project/app/app/places/models.py", line 13, in < module >
User = user_model()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py", line 150, in get_user_model return django_apps.get_model(settings.AUTH_USER_MODEL)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 19 4, in get_model
self.check_models_ready()
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 13 1, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren 't loaded yet.
I've searched any solutions on many sites but nothing helps. Is it problem with project files or maybe something with django?
I'm currently trying to setting up django-nose in my project.
I also used Djangae (https://djangae.readthedocs.org/en/latest/) for app engine compatibility.
I add 'django_nose' in my INSTALLED_APPS
I set TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
Launching "python manage.py test" is not raising any exceptions.
But when I want to launch the server with "python manage.py runserver", the server is running but when I try to call "localhost:8000" I get :
ERROR 2016-03-23 15:59:49,299 wsgi.py:263]
Traceback (most recent call last):
File "/Users/briva/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/briva/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Users/briva/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
__import__(cumulative_path)
File "/Users/briva/Desktop/dangoptest/dangoptest/wsgi.py", line 18, in <module>
application = DjangaeApplication(get_wsgi_application())
File "/Users/briva/Desktop/dangoptest/lib/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup()
File "/Users/briva/Desktop/dangoptest/lib/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/briva/Desktop/dangoptest/lib/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/briva/Desktop/dangoptest/lib/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "lib/django_nose/__init__.py", line 5, in <module>
from django_nose.runner import BasicNoseRunner, NoseTestSuiteRunner
File "lib/django_nose/runner.py", line 61, in <module>
from django.test.simple import DjangoTestSuiteRunner as DiscoverRunner
ImportError: No module named simple
Thanks for answers.
I'm trying to run single test using django-nose:
./manage.py test lead.tests:LeadStatTests.basic_stat_test
And following ImportError occurs:
======================================================================
ERROR: Failure: ImportError (cannot import name LeadSource)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/nose/loader.py", line 420, in loadTestsFromName
addr.filename, addr.module)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/kolen/items/someproject/lead/tests.py", line 16, in <module>
from lead.models import Lead, Action, LeadSource, LeadType, events_by_month, EventSummary
File "/Users/kolen/items/someproject/lead/models.py", line 38, in <module>
User = get_user_model()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 127, in get_user_model
user_model = get_model(app_label, model_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/db/models/loading.py", line 271, in get_model
self._populate()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/debug_toolbar/models.py", line 63, in <module>
patch_root_urlconf()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/debug_toolbar/models.py", line 51, in patch_root_urlconf
reverse('djdt:render_panel')
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 507, in reverse
app_list = resolver.app_dict[ns]
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 329, in app_dict
self._populate()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 267, in _populate
for pattern in reversed(self.url_patterns):
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 365, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 360, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/kolen/items/someproject/system/urls.py", line 8, in <module>
admin.autodiscover()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
import_module('%s.admin' % app)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/kolen/items/someproject/lead/admin.py", line 5, in <module>
from lead.models import LeadSource, LeadType, Lead, ........, \
ImportError: cannot import name LeadSource
Running all tests with ./manage.py test works. This exception occurs only when trying to run single test or test class. However running all tests takes too much time so I want a way to run single test.
Application and django admin works too. There's no __init__.py in root directory of the project.
Suddenly discovered that problem is caused by django-debug-toolbar. Removing it from the project solved this issue.
There is possibly duplicate of this question with similar problem also caused by django-debug-toolbar.
I have this line in my appliaction's init.py:
from .signals import *
When I run gunicorn myproject.wsgi:application, it gives me this error:
Traceback (most recent call last):
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
worker.init_process()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
self.wsgi = self.app.wsgi()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
__import__(module)
File "/webapps/venv/myproject/myproject/__init__.py", line 1, in <module>
from .signals import *
File "/webapps/venv/myproject/myproject/signals.py", line 1, in <module>
from django.db.models.signals import pre_delete
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/__init__.py", line 5, in <module>
from django.db.models.query import Q
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 17, in <module>
from django.db.models.deletion import Collector
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/deletion.py", line 4, in <module>
from django.db.models import signals, sql
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/__init__.py", line 4, in <module>
from django.db.models.sql.subqueries import *
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/subqueries.py", line 12, in <module>
from django.db.models.sql.query import Query
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 22, in <module>
from django.db.models.sql import aggregates as base_aggregates_module
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/aggregates.py", line 9, in <module>
ordinal_aggregate_field = IntegerField()
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 116, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/webapps/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/webapps/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Traceback (most recent call last):
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
worker.init_process()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
self.wsgi = self.app.wsgi()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
__import__(module)
File "/webapps/venv/myproject/myproject/__init__.py", line 1, in <module>
from .signals import *
File "/webapps/venv/myproject/myproject/signals.py", line 1, in <module>
from django.db.models.signals import pre_delete
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/__init__.py", line 5, in <module>
from django.db.models.query import Q
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 17, in <module>
from django.db.models.deletion import Collector
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/deletion.py", line 4, in <module>
from django.db.models import signals, sql
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/__init__.py", line 4, in <module>
from django.db.models.sql.subqueries import *
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/subqueries.py", line 12, in <module>
from django.db.models.sql.query import Query
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 22, in <module>
from django.db.models.sql import aggregates as base_aggregates_module
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/aggregates.py", line 9, in <module>
ordinal_aggregate_field = IntegerField()
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 116, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/webapps/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/webapps/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
If I disable the above-mentioned line in the __init__.py, gunicorn will start working.
Of course I can move the import line to another place and solve the issue, but I wonder why the error happens and if there's another way to resolve it.
By using the from .signals import * it seems you're getting an error due to the execution order.
Based on the error about DJANGO_SETTINGS_MODULE you need that defined in order to import from a model file. The issue I think is occurring is that the __init__.py file is getting executed when gunicorn goes to load your app, but before Django has actually loaded all of the application settings.
A potential fix may be to define the __all__ in your signals.py file.
Without more context to the issue though, it's tough to know.