2016-08-08 6 views
0

Nach dem Importieren eines meiner Modelle in einem Python-Skript, wenn ich den Localhost-Server ausführen, bekomme ich erro r, habe ich gelesen, aber alle meine Versuche waren ein fail:Django konnte Einstellungen nach dem Import eines Modells in einem Python-Skript nicht importieren

[email protected]_VM2:~/env_Compass4D/Compass4D$ python manage.py runserver 
Traceback (most recent call last): 
    File "manage.py", line 9, in <module> 
    execute_from_command_line(sys.argv) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line 
    utility.execute() 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 261, in fetch_command 
    commands = get_commands() 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 107, in get_commands 
    apps = settings.INSTALLED_APPS 
    File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 54, in __getattr__ 
    self._setup(name) 
    File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 49, in _setup 
    self._wrapped = Settings(settings_module) 
    File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 132, in __init__ 
    % (self.SETTINGS_MODULE, e) 
ImportError: Could not import settings 'Compass4D.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named Compass4D.settings 

Mein sys.path:

>>> import sys 
>>> print sys.path 
['', '/usr/lib/pymodules/python2.7', '/usr/local/lib/python2.7/site-packages', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol'] 

manage.py:

#!/usr/bin/env python 
import os 
import sys 

if __name__ == "__main__": 
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Compass4D.settings") 

    from django.core.management import execute_from_command_line 
    execute_from_command_line(sys.argv) 

wsgi.py:

import os 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Compass4D.settings") 

# This application object is used by any WSGI server configured to use this 
# file. This includes Django's development server, if the WSGI_APPLICATION 
# setting points here. 
from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application() 

Vielen Dank für Ihre Hilfe!

+0

Nun, ist der Ordner mit Einstellungen in sys.path? Ich habe es dort nicht gesehen. – Lucas03

+0

sys.path.insert (1, 'env_Compass4D/Compass4D/settings.py') >>> drucken sys.path ['', 'env_Compass4D/Compass4D/settings.py', ...] – Datex2

+0

der Fehler ist immer noch dort, und wenn ich Python-Konsole schließe, wird sys Pfad ohne den Pfad wiederhergestellt, den ich zuvor eingefügt hatte – Datex2

Antwort

0

Ich bestätige das Problem war, dass ich manage.py, settings.py und wsgi.py im selben Ordner hatte, dann können Sie appName.settings im Pfad import conf nicht schreiben, danke Jungs.

Verwandte Themen