question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

shell_plus --notebook not working in 1.7

See original GitHub issue

from docs looks like there’s a new setup() method.

---------------------------------------------------------------------------
AppRegistryNotReady                       Traceback (most recent call last)
<ipython-input-1-7474fc4fe95e> in <module>()
      [CODE ACCESSING MODELS VIA DJANGO ORM]

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\manager.pyc in manager_method(self, *args, **kwargs)
     90         def create_method(name, method):
     91             def manager_method(self, *args, **kwargs):
---> 92                 return getattr(self.get_queryset(), name)(*args, **kwargs)
     93             manager_method.__name__ = method.__name__
     94             manager_method.__doc__ = method.__doc__

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\query.pyc in filter(self, *args, **kwargs)
    687         set.
    688         """
--> 689         return self._filter_or_exclude(False, *args, **kwargs)
    690 
    691     def exclude(self, *args, **kwargs):

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\query.pyc in _filter_or_exclude(self, negate, *args, **kwargs)
    705             clone.query.add_q(~Q(*args, **kwargs))
    706         else:
--> 707             clone.query.add_q(Q(*args, **kwargs))
    708         return clone
    709 

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\sql\query.pyc in add_q(self, q_object)
   1285         existing_inner = set(
   1286             (a for a in self.alias_map if self.alias_map[a].join_type == self.INNER))
-> 1287         clause, require_inner = self._add_q(where_part, self.used_aliases)
   1288         self.where.add(clause, AND)
   1289         for hp in having_parts:

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\sql\query.pyc in _add_q(self, q_object, used_aliases, branch_negated, current_negated)
   1312                 child_clause, needed_inner = self.build_filter(
   1313                     child, can_reuse=used_aliases, branch_negated=branch_negated,
-> 1314                     current_negated=current_negated, connector=connector)
   1315                 joinpromoter.add_votes(needed_inner)
   1316             target_clause.add(child_clause, connector)

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\sql\query.pyc in build_filter(self, filter_expr, branch_negated, current_negated, can_reuse, connector)
   1136         if not arg:
   1137             raise FieldError("Cannot parse keyword query %r" % arg)
-> 1138         lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
   1139 
   1140         # Work out the lookup type and remove it from the end of 'parts',

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\sql\query.pyc in solve_lookup_type(self, lookup)
   1074             if aggregate:
   1075                 return aggregate_lookups, (), aggregate
-> 1076         _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
   1077         field_parts = lookup_splitted[0:len(lookup_splitted) - len(lookup_parts)]
   1078         if len(lookup_parts) == 0:

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\sql\query.pyc in names_to_path(self, names, opts, allow_many, fail_on_missing)
   1337                 name = opts.pk.name
   1338             try:
-> 1339                 field, model, direct, m2m = opts.get_field_by_name(name)
   1340             except FieldDoesNotExist:
   1341                 # We didn't found the current field, so move position back

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\options.pyc in get_field_by_name(self, name)
    414                 return self._name_map[name]
    415             except AttributeError:
--> 416                 cache = self.init_name_map()
    417                 return cache[name]
    418         except KeyError:

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\options.pyc in init_name_map(self)
    443         # We intentionally handle related m2m objects first so that symmetrical
    444         # m2m accessor names can be overridden, if necessary.
--> 445         for f, model in self.get_all_related_m2m_objects_with_model():
    446             cache[f.field.related_query_name()] = (f, model, False, True)
    447         for f, model in self.get_all_related_objects_with_model():

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\options.pyc in get_all_related_m2m_objects_with_model(self)
    559             cache = self._related_many_to_many_cache
    560         except AttributeError:
--> 561             cache = self._fill_related_many_to_many_cache()
    562         return list(six.iteritems(cache))
    563 

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\options.pyc in _fill_related_many_to_many_cache(self)
    573                 else:
    574                     cache[obj] = model
--> 575         for klass in self.apps.get_models():
    576             if not klass._meta.swapped:
    577                 for f in klass._meta.local_many_to_many:

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\utils\lru_cache.pyc in wrapper(*args, **kwds)
     99                         stats[HITS] += 1
    100                         return result
--> 101                     result = user_function(*args, **kwds)
    102                     cache[key] = result
    103                     stats[MISSES] += 1

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\apps\registry.pyc in get_models(self, app_mod, include_auto_created, include_deferred, include_swapped)
    166         Set the corresponding keyword argument to True to include such models.
    167         """
--> 168         self.check_models_ready()
    169         if app_mod:
    170             warnings.warn(

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\apps\registry.pyc in check_models_ready(self)
    129         """
    130         if not self.models_ready:
--> 131             raise AppRegistryNotReady("Models aren't loaded yet.")
    132 
    133     def get_app_configs(self):

AppRegistryNotReady: Models aren't loaded yet.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:20 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
jrjames83commented, Aug 25, 2017

Was dealing with this yesterday. Putting the following in my jupyter notebook before all the model imports helped circumvent and get back to fiddling:

import os, django
django.setup()

Relevant Modules

Django==1.10.1 django-debug-toolbar==1.8 django-extensions==1.8.1

ipykernel==4.6.1 ipython==6.1.0 ipython-genutils==0.2.0 ipywidgets==7.0.0

jupyter==1.0.0 jupyter-client==5.1.0 jupyter-console==5.2.0 jupyter-core==4.3.0

0reactions
ehacinomcommented, Mar 1, 2018

If the settings file is at PATH_TO_APP/APP/settings.py:

import sys, os, django
sys.path.append("PATH_TO_APP")
os.environ['DJANGO_SETTINGS_MODULE'] = 'APP.settings'
django.setup()
Read more comments on GitHub >

github_iconTop Results From Across the Web

shell_plus — django-extensions-shell 1.7.4 documentation
The Django settings module and database models are auto-loaded into the interactive shell's global namespace also for IPython Notebook. Auto-loading is done by ......
Read more >
Running django unit tests from shell with ipython notebook ...
In my case, I just created a test_runner function that accepts a test_class parameter, like this: def test_runner(test_class): from ...
Read more >
python manage.py shell_plus --notebook - You.com
I'm running an IPython notebook through Django's shell_plus with the following command: sudo ./manage.py shell_plus --notebook. I'm not entirel sure how it ...
Read more >
Jupyter Notebook in PyCharm IDE not displaying inline ...
In working more with Jupyter notebooks in PyCharm, I have noticed that if I try and print several inline images (or if I...
Read more >
Using IPython Notebook with Django - Andrew Brookins
The latest version of the Django Extensions app on Github has support for using the shell_plus command with Notebook. If you're up to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found