我正在设置一个新的django项目,我遇到了可怕的“无法导入设置”错误。我以前建立了很多django项目,从来没有遇到过这个问题。与这一点的不同之处在于它使用的是python3.4,django 1.7,并且它位于VM上(我的所有其他人都在< 1.7,python 2和物理主机上)。我已经用Google搜索了这个问题并且问了很多,但这些解决方案都不适用于我。
这是我得到的错误:
vagrant@vagrant:/vagrant/elex_apis$ python3 manage.py migrate
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py",
line 94, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
File "<frozen importlib._bootstrap>", line 2189, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
File "<frozen importlib._bootstrap>", line 2201, in _find_and_load_unlocked
ImportError: No module named '/vagrant/elex_apis/elex_apis/settings'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py",
line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py",
line 345, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py",
line 46, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py",
line 42, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py",
line 98, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings
'/vagrant/elex_apis/elex_apis/settings.py' (Is it on sys.path? Is
there an import error in the settings file?): No module named
'/vagrant/elex_apis/elex_apis/settings'
我检查了所有常见的事情(设置文件在那里,它是 可读,我有 init ,py文件,我的wsgi.py很好,我的manage.py 很好,我可以导入它)
vagrant@vagrant:/vagrant/elex_apis$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import elex_apis.settings
>>>
非常感谢任何帮助。
答案 0 :(得分:1)
通常No module named
例外不包含路径,而是包含模块名称(带点)。试着找出你获得路径的原因,检查你的DJANGO_SETTINGS_MODULE
环境变种