2016-04-07 2 views
0

Ich habe ein Projekt sagen MyProject mit der angegebenen Verzeichnisstruktur, wo die Anwendungen im Verzeichnis applications installiert sind.Django 1.9 ImportError: Kein Modul mit dem Namen 'appname' auf der Shell

. 
├── 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 

Mein polls/apps.py Inhalt ist

from __future__ import unicode_literals 

from django.apps import AppConfig 


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

und der polls/__init__.py Inhalt,

default_app_config='applications.polls.apps.PollConfig' 

und die INSTALLED_APPS in Einstellungen,

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

die Schale wirft ImportError: No module named polls

Wie behebe ich es?

vielen Dank.

Update (fügt 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 Zurückverfolgungs

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' 

Antwort

3

Sie benötigen einen __init__.py Datei unter Anwendungsverzeichnis zu erstellen und es als Paket/Modul zu verwenden.

eine Datei applications/__init__.py

+0

oder in Ihrer INSTALLED_APPS, einfach 'Umfragen' – harryr

+0

OP verwendet ein einziges Paket, um alle Anwendungen zu enthalten, weshalb er 'applications.polls' verwendet. – v1k45

+0

oops, das ist nur ein Tippfehler Ich habe tatsächlich eine Init-Datei dort. habe andere Apps ausgelassen. mit '__inti __. py' bekomme ich den gleichen Fehler. – Marty

0

auch genannt, wenn Sie django shell bedeuten oder, wenn Sie gerade mit Ihrer App-Shell aus einem Python haben Sie dann zum ersten import django dann rufen django.setup() arbeiten wollen.

+0

ich meine' Python manage.py Shell' – Marty

+0

Ich meine auch, tut mir leid für den Aufruf es 'Django Shell'. – sehrob

+0

Haben Sie versucht, '__init __. Py' im Anwendungsordner hinzuzufügen? Auch 'code' ist ein eingebautes Modul und es hat' interactive' Methode, also ist alles in Ordnung mit deiner Python Installation? – sehrob

Verwandte Themen