You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PyDev调试时出现AppRegistryNotReady错误,如何解决?

AppRegistryNotReady: Apps aren't loaded yet when debugging Django app in PyDev

Problem

When debugging a Django application with PyDev in Eclipse, I encounter the following AppRegistryNotReady error:

pydev debugger: starting (pid: 21100) Traceback (most recent call last): File "D:\python tools\eclipse-java-oxygen-3a-win32-x86_64\eclipse\dropins\plugins\org.python.pydev.core_6.3.2.201803171248\pysrc\pydevd.py", line 1621, in <module> main() File "D:\python tools\eclipse-java-oxygen-3a-win32-x86_64\eclipse\dropins\plugins\org.python.pydev.core_6.3.2.201803171248\pysrc\pydevd.py", line 1615, in main globals = debugger.run(setup['file'], None, None, is_module) File "D:\python tools\eclipse-java-oxygen-3a-win32-x86_64\eclipse\dropins\plugins\org.python.pydev.core_6.3.2.201803171248\pysrc\pydevd.py", line 1022, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Users\Kevin\Desktop\python\django\webapp\app01\views.py", line 12, in <module> from app01.models import FristModel File "C:\Users\Kevin\Desktop\python\django\webapp\app01\models.py", line 8, in <module> class FristModel (models.Model): File "C:\Python27\lib\site-packages\django-1.11.13-py2.7.egg\django\db\models\base.py", line 110, in __new__ app_config = apps.get_containing_app_config(module) File "C:\Python27\lib\site-packages\django-1.11.13-py2.7.egg\django\apps\registry.py", line 247, in get_containing_app_config self.check_apps_ready() File "C:\Python27\lib\site-packages\django-1.11.13-py2.7.egg\django\apps\registry.py", line 125, in check_apps_ready raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

The error indicates that Django's apps haven't finished loading when the debugger tries to execute the script. How can I resolve this for PyDev debugging?


Answer

This error crops up because PyDev’s default way of running/debugging a single Python file doesn’t trigger Django’s full app initialization process. Here are actionable fixes tailored to your setup:

1. Use PyDev's dedicated Django run/debug configuration

This is the simplest and most reliable fix:

  • Right-click your Django project in Eclipse’s Project Explorer
  • Hover over Run As and select PyDev: Django
  • If prompted, confirm your project’s settings module (it should auto-detect something like webapp.settings)

This method ensures Django loads all registered apps before executing your code, completely avoiding the AppRegistryNotReady error.

2. Manually initialize Django in your target file

If you need to debug a specific module (like views.py) directly, add this initialization code at the very top of the file:

import django
from django.conf import settings

# Update these settings to match your project's config
if not settings.configured:
    settings.configure(
        DEBUG=True,
        SECRET_KEY='your-project-secret-key',
        INSTALLED_APPS=[
            'django.contrib.admin',
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'django.contrib.sessions',
            'django.contrib.messages',
            'django.contrib.staticfiles',
            'app01',  # Include your app here
        ],
        DATABASES={
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': 'db.sqlite3',
            }
        }
    )
django.setup()

This code manually triggers Django’s app registry setup before any model/view imports that depend on it.

3. Fix your PyDev run configuration

If you prefer using a custom run/debug setup:

  • Go to Run > Run Configurations
  • Create or edit your PyDev Python configuration
  • Under the Arguments tab, set Program arguments to runserver
  • Under the Environment tab, add a variable:
    • Name: DJANGO_SETTINGS_MODULE
    • Value: Your project’s settings module path (e.g., webapp.settings)
  • Under the Interpreter tab, verify you’re using the Python 2.7 interpreter that has Django 1.11 installed

4. Check for circular imports

Sometimes this error hides a circular import issue (e.g., importing a view inside a model, or vice versa). Double-check your imports:

  • Avoid importing views at the top of models.py and vice versa
  • If you need cross-references, use lazy imports like:
    from django.utils.module_loading import import_string
    
    # Use this when you need the model/view instead of importing at the top
    MyModel = import_string('app01.models.FristModel')
    

内容的提问来源于stack exchange,提问作者Kevin U

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:21:29