python - django.core.exceptions.AppRegistryNotReady : Apps aren't loaded yet launching debug on pycharm

标签 python python-3.x django pycharm virtualenv

我有一个使用 python 2.7.10 运行的 Django(1.9 版)应用程序,我正在使用 Virtualenv。 使用 ./manage.py runserver 运行应用程序我没有错误,但是当我尝试在调试中运行时我得到 django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet .

Pycharm调试配置如下:

知道为什么吗? 这是完整的堆栈跟踪:

   /Users/matteobetti/Progetti/Enydros/enysoft/bin/python ./manage.py runserver
    Traceback (most recent call last):
      File "./manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
        utility.execute()
      File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 176, in fetch_command
        commands = get_commands()
      File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/utils/lru_cache.py", line 100, in wrapper
        result = user_function(*args, **kwds)
      File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 71, in get_commands
        for app_config in reversed(list(apps.get_app_configs())):
      File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
        self.check_apps_ready()
      File "/Users/matteobetti/Progetti/Enydros/enysoft/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.

我在 execute_from_command_line(sys.argvs) 之前添加 import django e django.setup

我得到了这个堆栈跟踪:

Traceback (most recent call last):
  File "/Users/matteobetti/Progetti/Enydros/enysoft/manage.py", line 10, in <module>
    django.setup()
  File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/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 "/Users/matteobetti/Progetti/Enydros/enysoft/frontend/apps.py", line 2, in <module>
    from frontend.services.container import app_context
  File "/Users/matteobetti/Progetti/Enydros/enysoft/frontend/services/container.py", line 1, in <module>
    from frontend.services.enysoft_services import RService, FixedSizeDirectoryCache, TubeSectionService, CsvSanifier
  File "/Users/matteobetti/Progetti/Enydros/enysoft/frontend/services/enysoft_services.py", line 5, in <module>
    import rpy2.robjects as ro
  File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/rpy2/robjects/__init__.py", line 15, in <module>
    import rpy2.rinterface as rinterface
  File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/rpy2/rinterface/__init__.py", line 16, in <module>
    tmp = subprocess.check_output(("R", "RHOME"), universal_newlines=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

另一件事是,我的 Linux 同事对相同的 virtualenv 配置没有问题,唯一有问题的是我,使用 MacOs。

最佳答案

尝试将您的设置文件添加到系统 PATH。在我的项目中,设置位于文件夹/project_name/project_name/settings/development.py(与标准方式略有不同)。在我的例子中,环境变量字符串是

DJANGO_SETTINGS_MODULE=project_name.settings.development;PYTHONUNBUFFERED=1

因此根据您的参数更改它,然后再次尝试运行服务器。我希望这会有所帮助。

关于python - django.core.exceptions.AppRegistryNotReady : Apps aren't loaded yet launching debug on pycharm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38600097/

相关文章:

python - 使用 "Flatten"或 "Reshape"在keras中获取未知输入形状的一维输出

python - 在 Chef 服务器中,如何确定节点何时完全引导

python - Python 处理二进制文件有危险吗?

Python计算时间差,在1中给出 ‘years, months, days, hours, minutes and seconds’

python - Sentry - 清理局部变量敏感数据

python - werkzeug + django + Gunicorn : TypeError

Python 3 类型错误 : bytes or integer address expected instead of str instance

python-3.x - 使用 SSLContext 指定 IP 地址 + SNI

python - sqlite 真空与 django

jquery - 如何通过表单元素传递 json