ImportError: No module named local
ImportError: No module named local
我正在尝试 运行 文件 manage.py
,其代码如下
#!/usr/bin/env python
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local')
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django # noqa
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
# This allows easy placement of apps within the interior
# myproject directory.
current_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(current_path, 'myproject'))
execute_from_command_line(sys.argv)
使用以下命令:
python manage.py runserver_plus 0.0.0.0:8000
但我得到以下回溯:
Traceback (most recent call last):
File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 308, in execute
settings.INSTALLED_APPS
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named local
我不知道如何解释这个回溯来修复错误。你能帮忙吗?
根据您提供的代码和错误消息,我最好的猜测是为 DJANGO_SETTINGS_MODULE
提供的模块路径是错误的:config.settings.local
.
要使此路径有效,您需要如下目录结构:
/
├── manage.py
├── config/
| ├── __init__.py
| ├── settings/
| | ├── __init__.py
| | ├── local.py
您的项目结构是这样的吗(包括 __init__.py
文件)?如果不是,要么修改你的目录结构,要么修改DJANGO_SETTINGS_MODULE
.
的值
我正在尝试 运行 文件 manage.py
,其代码如下
#!/usr/bin/env python
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local')
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django # noqa
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
# This allows easy placement of apps within the interior
# myproject directory.
current_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(current_path, 'myproject'))
execute_from_command_line(sys.argv)
使用以下命令:
python manage.py runserver_plus 0.0.0.0:8000
但我得到以下回溯:
Traceback (most recent call last):
File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 308, in execute
settings.INSTALLED_APPS
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named local
我不知道如何解释这个回溯来修复错误。你能帮忙吗?
根据您提供的代码和错误消息,我最好的猜测是为 DJANGO_SETTINGS_MODULE
提供的模块路径是错误的:config.settings.local
.
要使此路径有效,您需要如下目录结构:
/
├── manage.py
├── config/
| ├── __init__.py
| ├── settings/
| | ├── __init__.py
| | ├── local.py
您的项目结构是这样的吗(包括 __init__.py
文件)?如果不是,要么修改你的目录结构,要么修改DJANGO_SETTINGS_MODULE
.