0

I would like to use Django to create an app but got an error

"ImportError: No module named books.apps" after running:

python manage.py startapp books

Error message:

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

Any idea what went wrong? Thanks!

PRMoureu
  • 12,817
  • 6
  • 38
  • 48
dave
  • 229
  • 1
  • 3
  • 13

1 Answers1

0

You must first start a project before trying to start an app. First run:

python manage.py startproject mysite

and replace "mysite" with what you want to call your project. Then run:

python manage.py startapp books

See the docs here.

Dewald Abrie
  • 1,392
  • 9
  • 21
  • Thanks Dewald! I used an alternate solution mentioned here: https://stackoverflow.com/questions/25244631/models-arent-loaded-yet-error-while-populating-in-django-1-8-and-python-2-7-8/25244833#25244833 and it works! Not sure why though. I think it's because of the Django version I'm using. – dave Aug 27 '17 at 22:23