(moving back on-list so that others can jump in to help)

Short answer: check in settings.py to make sure that INSTALLED_APPS doesn't
list the same app name twice.

------

Okay, this is different!

We tried to "stimulate the error" *, and we've found that on closer
inspection that the same SyntaxError is not reliably reproducible.
That is strange. However, it is worth asking yourself it you want to track
it down. You could choose not to because the point where you run into this
is where another error is getting raised:
django.core.exceptions.ImproperlyConfigured. You'll have to address that
anyway, so lets turn our
attention to that first.

Looking at the part of the code that raises it
<https://github.com/django/django/blob/master/django/apps/registry.py#L87>,
you'll see it means that you have two apps with the same name. To figure
out which app that is,
lets stick pdb into the code and print the relevant list of installed apps.
# Load app configs and app modules.
for entry in installed_apps:
    if isinstance(entry, AppConfig):
        app_config = entry
    else:
        app_config = AppConfig.create(entry)
    if app_config.label in self.app_configs:
        import pdb; pdb.set_trace()
        print([ac.label for ac in installed_apps if isinstance(ac,
AppConfig)])
        print([str(ac) for ac in installed_apps if not isinstance(ac,
AppConfig)])
        raise ImproperlyConfigured(
            "Application labels aren't unique, "
            "duplicates: %s" % app_config.label)

If you haven't used pdb before, I recommend checking through the pdb docs
<https://docs.python.org/2/library/pdb.html>. Pdb is super-useful in
general. The app will stop at the point where `import pdb;pdb.set_trace()`
is and
wait for you to do something in the python shell it opens for you. You can
print variables with 'p', display a stack trace with 'w', jump up or down
the call stack, and a few other useful things.
Print the values in installed_apps and you should be able to find the name
of the duplicated app.

Note that if you accidentally leave that `import pdb; pdb.set_trace()` in
there, it will cause your app to wait forever. You can use The Platinum
Searcher <https://github.com/monochromegane/the_platinum_searcher> to check
for all examples of a string in a codebase.

-- Andrew M. Farrell


*  This phrase comes from David J. Aggan's book Debugging: The 9
Indispensable Rules
<http://www.amazon.com/Debugging-Indispensable-Software-Hardware-Problems/dp/0814474578>,
which I recommend for the same reasons this guy does
<http://www.dwheeler.com/essays/debugging-agans.html>.


On Mon, Dec 7, 2015 at 3:44 AM, Emmanuel Olodun <ihimo...@googlemail.com>
wrote:

> Hi Andrew
> thanks for your help but am still getting an error message:-
>
> Traceback (most recent call last):
>   File "C:\Users\LENOVO\Documents\testsyntax.py", line 9, in <module>
>     "duplicates: %s" % app_config.label)
> Exception: Application labels aren't unique, duplicates: herring
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2By5TLYuNVOKwww7FFwGUMpaBYNwc0r5%3D5wx%3DPLbS53vQmZ5ag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to