Python,Django:ImportError:没有名为本地的模块

时间:2019-02-10 03:30:54

标签: django python-2.7 traceback

我正在尝试运行以下代码的文件DT The NNP Fulton NNP County NNP Grand NNP Jury VBD said NNP Friday DT an NN investigation ...

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

我不知道如何解释此追溯以修复错误。你能帮忙吗?

1 个答案:

答案 0 :(得分:2)

从您提供的代码和错误消息中,我最好的猜测是为config.settings.local提供的模块路径是错误的:/ ├── manage.py ├── config/ | ├── __init__.py | ├── settings/ | | ├── __init__.py | | ├── local.py

要使此路径有效,您将需要以下目录结构:

__init__.py

您的项目结构是什么样(包括DJANGO_SETTINGS_MODULE文件)?否则,请修改您的目录结构,或修改import matplotlib.pyplot as plt plt.grid(True) plt.show(True) 的值。