ImportError:没有名为books.apps的模块(Django)

时间:2017-08-27 21:48:18

标签: python django django-models

我想使用Django创建一个应用程序但是出错了

  

“ImportError:运行时没有名为books.apps的模块”:

python manage.py startapp books

错误讯息:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 324, in execute
    django.setup()
  File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/apps/config.py", line 116, in create
    mod = import_module(mod_path)
  File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named books.apps

知道出了什么问题吗?谢谢!

1 个答案:

答案 0 :(得分:0)

在尝试启动应用之前,您必须先启动项目。首先运行:

python manage.py startproject mysite

并将“mysite”替换为您想要调用项目的内容。然后运行:

python manage.py startapp books

查看文档here