-1

I have a project say MyProject with the given directory structure, where the apps are installed in the applications directory.

.
├── myapp
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── applications
│   └── polls
│       ├── admin.py
│       ├── apps.py
│       ├── __init__.py
│       ├── models.py
│       ├── tests.py
│       └── views.py
├── db.sqlite3
├── manage.py
└── wsgi
    ├── static
    │   └── keep.me
    └── wsgi.py

My polls/apps.py content is

from __future__ import unicode_literals

from django.apps import AppConfig


class PollConfig(AppConfig):
    name = 'applications.polls'

and the polls/__init__.py content,

default_app_config='applications.polls.apps.PollConfig'

and the INSTALLED_APPS in settings,

INSTALLED_APPS = [
    ......
    ......
    'applications.polls'
]

the shell throws ImportError: No module named polls

How do I fix it?

thank you so much.

update (adds traceback)

Traceback (most recent call last):
  File "<input>", line 5, in <module>
  File "/home/marty/.virtualenvs/dj19/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/marty/.virtualenvs/dj19/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/home/marty/.virtualenvs/dj19/local/lib/python2.7/site-packages/django/apps/config.py", line 123, in create
    import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/opt/pycharm-5.0.3/helpers/pydev/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: No module named polls

update: python manage.py shell traceback

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/marty/.virtualenvs/dj19/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/marty/.virtualenvs/dj19/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/marty/.virtualenvs/dj19/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/marty/.virtualenvs/dj19/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/marty/.virtualenvs/dj19/local/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 101, in handle
    code.interact(local=imported_objects)
AttributeError: 'module' object has no attribute 'interact'
All Іѕ Vаиітy
  • 24,861
  • 16
  • 87
  • 111

2 Answers2

3

You need to create a __init__.py file under applications directory to use it as a package/ module.

create a file named applications/__init__.py

v1k45
  • 8,070
  • 2
  • 30
  • 38
0

Also, if you mean django shell or if you just want to work with your app from within a python shell then you have to first import django then call django.setup().

sehrob
  • 1,034
  • 12
  • 24
  • I also mean this, sorry for calling it `django shell`. – sehrob Apr 08 '16 at 04:07
  • Did you tried to add `__init__.py` in applications folder? Also `code` is a built-in module and it has `interact` method, so is everything alright with your python installation? – sehrob Apr 08 '16 at 04:25