Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - ImportError: No module named apps

I am trying out the Django tutorial on the djangoproject.com website, but when I reach the part where I do the first "makemigrations polls" I keep getting this error:

ImportError: No module named apps

Traceback (most recent call last):
  File "manage.py", line 22, in 
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/Library/Python/2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Library/Python/2.7/site-packages/django/apps/config.py", line 112, in create
    mod = import_module(mod_path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)

How can I resolve this error?

like image 612
Monil Avatar asked Sep 16 '16 03:09

Monil


People also ask

How do I fix Django error module not found?

The Python "ModuleNotFoundError: No module named 'django'" occurs when we forget to install the Django module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install Django command.

What is Django w3schools?

What is Django? Django is a Python framework that makes it easier to create web sites using Python. Django takes care of the difficult stuff so that you can concentrate on building your web applications.

What is Django application?

Django is a high-level Python web framework that enables rapid development of secure and maintainable websites. Built by experienced developers, Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel.


2 Answers

Your problem is that your Django version does not match the version of the tutorial.

In Django 1.9+, the startapp command automatically creates an app config class, so the tutorial asks you to add polls.apps.PollsConfig to INSTALLED_APPS.

For Django 1.8 and earlier, the tutorial asks you to add polls to INSTALLED_APPS. If you add polls.apps.PollsConfig instead, you will get an import error, unless you create the PollsConfig manually.

like image 185
Alasdair Avatar answered Oct 04 '22 20:10

Alasdair


There is an error in the tutorial.

It instructs to add polls.apps.PollsConfig in the INSTALLED_APPS section of the settings.py file. I changed it from polls.apps.PollsConfig to simply polls and that did the trick. I was able to successfully make migrations.

I hope this helps other people who face similar problems.

like image 37
Monil Avatar answered Oct 04 '22 20:10

Monil