am new to django and at a dead end or so i think

66 views
Skip to first unread message

Emmanuel Olodun

unread,
Dec 3, 2015, 11:06:29 AM12/3/15
to Django users
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\LENOVO>django-admin.py
Traceback (most recent call last):
  File "C:\Python27\Scripts\django-admin.py", line 2, in <module>
    from django.core import management
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
10, in <module>
    from django.apps import apps
  File "C:\Python27\lib\site-packages\django\apps\__init__.py", line 2, in <modu
le>
    from .registry import apps      # NOQA
  File "C:\Python27\lib\site-packages\django\apps\registry.py", line 89
    duplicates: %s" % app_config.label)
             ^
SyntaxError: invalid syntax

C:\Users\LENOVO>

this is th error message i've been getting for like 2weeks now pls somebody help!!!!

Andrew Farrell

unread,
Dec 3, 2015, 11:49:27 AM12/3/15
to django...@googlegroups.com
Hi Emanuel,

That syntax error is getting raised from here: https://github.com/django/django/blob/master/django/apps/registry.py#L89

To check the validity of that syntax, I created a file with the following code:
``` 
class AppLabel(object):
    def __init__(self):
        self.label = 'herring'
app_config = AppLabel()
if True:
    raise Exception(
        "Application labels aren't unique, "
        "duplicates: %s" % app_config.label)
```
And ran it. It did not raise a syntax error. Could you try saving that code to a file, naming it testsyntax.py and then running it with

C:\Users\LENOVO> python testsyntax.py

I'm running on OSx. I don't know why the syntax should fail in one case and succeed in the other, but it is worth a try.

-- Andrew Farrell

--
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...@googlegroups.com.
To post to this group, send email to django...@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/2cb7ed54-35ab-4b0c-8d4d-5fb88071d097%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Farrell

unread,
Dec 7, 2015, 2:13:24 PM12/7/15
to Emmanuel Olodun, django...@googlegroups.com
(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, 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. 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 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, which I recommend for the same reasons this guy does.


On Mon, Dec 7, 2015 at 3:44 AM, Emmanuel Olodun <ihim...@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


Reply all
Reply to author
Forward
0 new messages