【发布时间】:2016-08-08 15:08:55
【问题描述】:
在python脚本中导入我的一个模型后,当我运行本地主机服务器时,我得到了这个error,我一直在阅读,但我所有的尝试都失败了:
ubuntu@INN0095_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
我的系统路径:
>>> 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()
感谢您的帮助!
【问题讨论】:
-
好吧,你的文件夹是 sys.path 中的设置吗?我在那里没看到。
-
sys.path.insert(1,'env_Compass4D/Compass4D/settings.py') >>> 打印 sys.path ['', 'env_Compass4D/Compass4D/settings.py',... ]
-
错误仍然存在,当我关闭python控制台时,sys路径恢复,没有我之前插入的路径
-
我认为问题可能是我在同一个文件夹中有 settings.py 和 manage.py
标签: python django django-wsgi