简体   繁体   English

没有名为foo.settings的模块Django导入错误

[英]No module named foo.settings Django Import Error

I'm gettings a Django import error after just cloning a repo for the first time, and I've looked at all previous questions and can't figure out what my problem is... 第一次克隆存储库后,我收到了Django导入错误,我查看了之前的所有问题,无法弄清楚我的问题是什么...

Traceback (most recent call last):
  File "manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 302, in execute
    settings.INSTALLED_APPS
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
    self._setup(name)
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 99, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named foo.settings

But I have my settings.py file in the foo directory? 但是我在foo目录中有settings.py文件吗?

Project 项目

app1 app1

app2 app2

foo

settings.py settings.py

wsgi.py wsgi.py

urls.py urls.py

app3 app3

manage.py manage.py

I am really confused. 我真的很困惑。 Here is my manage.py 这是我的manage.py

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


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

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

For Python to recognise a directory as a module, it needs to contain a file named __init__.py . 为了让Python将目录识别为模块,它需要包含一个名为__init__.py的文件。 This file can be empty, or can contain module top-level code. 该文件可以为空,或者可以包含模块顶级代码。

From the Python documentation : Python文档中

The __init__.py files are required to make Python treat the directories as containing packages __init__.py文件是使Python将目录视为包含包的必需文件

Related SO Question: What is __init__.py for? 相关的SO问题: __init__.py的作用是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM