Opened 10 years ago

Closed 10 years ago

#23470 closed Bug (invalid)

Django 1.7 app config ImportError: No module named appname.apps

Reported by: Renat Mennanov Owned by: nobody
Component: Core (Other) Version: 1.7
Severity: Normal Keywords: import error
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm trying to setup a custom application configuration for one of my Django app called 'articles' following the documentation at https://docs.djangoproject.com/en/dev/ref/applications/, but I keep getting ImportError: No module named articles.apps when execute ./manage.py check (or any other management command such as ./manage.py runserver)

This is a tree of the project

projectname
    ├── apps
    │   ├── articles
    │   │   ├── admin.py
    │   │   ├── apps.py
    │   │   ├── __init__.py
    │   │   ├── migrations
    │   │   │   ├── 0001_initial.py
    │   │   │   └── __init__.py
    │   │   ├── models.py
    │   │   ├── templates
    │   │   │   └── articles
    │   │   ├── templatetags
    │   │   │   ├── articles_tags.py
    │   │   │   └── __init__.py
    │   │   ├── tests.py
    │   │   ├── urls.py
    │   │   └── views.py
    │   ├── __init__.py

Contents of articles/init.py:

# articles/__init__.py
default_app_config = 'articles.apps.ArticlesConfig'

Contents of articles/apps.py:

# -*- coding: utf-8 -*-
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _


class ArticlesConfig(AppConfig):

    name = 'articles'
    verbose_name = _(u'Articles')

And I have 'projectname.apps.articles' in my INSTALLED_APPS

Just to ensure that I really have all these files and haven't messed up with paths

>>> from projectname.apps.articles.apps import ArticlesConfig
>>> ArticlesConfig
<class 'projectname.apps.articles.apps.ArticlesConfig'>

Everything imports just fine...

But:

(vagrant)vagrant@vagrant-ubuntu-trusty-32:~/django$ ./manage.py check
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/home/vagrant/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/vagrant/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/home/vagrant/local/lib/python2.7/site-packages/django/apps/config.py", line 112, in create
    mod = import_module(mod_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named articles.apps

Running on vagrant-ubuntu-trusty-32,

(vagrant)vagrant@vagrant-ubuntu-trusty-32:~/django$ pip freeze
Django==1.7
Fabric==1.10.0
Pillow==2.5.3
argparse==1.2.1
django-classy-tags==0.5.1
-e git+https://github.com/sehmaschine/django-grappelli.git@79f6005b0fef6ee8c665e78a10c80f20c510cd1b#egg=django_grappelli-master
django-mptt==0.6.1
django-sekizai==0.7
ecdsa==0.11
paramiko==1.14.1
psycopg2==2.5.2
pycrypto==2.6.1
python-memcached==1.53
pytils==0.3
sorl-thumbnail==11.12.1b
wsgiref==0.1.2
INSTALLED_APPS = (
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'grappelli.dashboard',
    'mptt',
    'sekizai',
    'pytils',
    'sorl.thumbnail',
    'projectname.apps.utils',
    'projectname.apps.seo',
    'projectname.apps.staticpages',
    'projectname.apps.statictext',
    'projectname.apps.usersettings',
    'projectname.apps.navigation',
    'projectname.apps.slideshow',
    'projectname.apps.articles',
    'projectname.apps.promo',
)

Change History (4)

comment:1 by Collin Anderson, 10 years ago

You need to be consistent about the prefixes you're using to referencing modules.

default_app_config = 'articles.apps.ArticlesConfig'
should be
default_app_config = 'projectname.apps.articles.apps.ArticlesConfig'

in reply to:  1 comment:2 by Renat Mennanov, 10 years ago

Replying to collinanderson:

You need to be consistent about the prefixes you're using to referencing modules.

default_app_config = 'articles.apps.ArticlesConfig'
should be
default_app_config = 'projectname.apps.articles.apps.ArticlesConfig'

I've set it to:

default_app_config = 'sefaro.apps.articles.apps.ArticlesConfig'

Now I get:

(vagrant)vagrant@vagrant-ubuntu-trusty-32:~/django$ ./manage.py check
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/home/vagrant/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/vagrant/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/home/vagrant/local/lib/python2.7/site-packages/django/apps/config.py", line 137, in create
    app_module = import_module(app_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named articles

comment:3 by Collin Anderson, 10 years ago

and your INSTALLED_APPS has "projectname.apps.articels", not "articles"?

Is there anywhere in your code where you're importing things directly from "articles" instead of "projectname.apps.articles"?

comment:4 by Tim Graham, 10 years ago

Resolution: invalid
Status: newclosed

Sorry to interrupt, but we try to avoid using this bug tracker as a support channel.

Please see TicketClosingReasons/UseSupportChannels for ways to get help, thanks!

Note: See TracTickets for help on using tickets.
Back to Top