Skip to content Skip to sidebar Skip to footer

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:

Solution 1:

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.

Solution 2:

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.

Solution 3:

I had a really similar issue, but one that was definitely different than the OP. That said, this post was one of the first responses I found when debugging my issue, so I'm hijacking it with an answer to my question.

Problem

The app I was building had apps nested beneath a parent namespace, e.g. customapp.polls instead of just polls. The error I saw was

ModuleNotFoundError: No module named 'polls'

but probably looks like the following if you're on Python 3.5 or older:

ImportError: No module named polls

Note that this says polls instead of apps in the original post.

Answers from this post

  • @Alasdair's answer is a good one to try. If I force a similar issue, I get an error about customapp.polls.apps.PollsConfig and customapp.polls.apps being missing instead of apps, but that could just be differences in versions.
  • @Monil's answer "solved" my issue, even though I had a PollsConfig subclass defined. As @Alasdair suggests, the reason that works is often because you didn't add an AppConfig subclass.

Solution

In my case, the error complained about the polls module being missing (not apps). And since @Monils answer "solved" my issue, I was able to narrow it down to my actual configuration. My config looked equivalent to:

class PollsConfig(AppConfig):
    name = 'polls'

but since I put my apps underneath a parent module, I should have written:

class PollsConfig(AppConfig):
    name = 'customapp.polls'

Solution 4:

You need to install required packages in your virtualenv to run Django project. First and foremost create virtualenv for your project.

virtualenv env#For python 2.7
virtualenv -p python3 env#For python 3.4

Actiavte env to install your requirements.

sourceenv/bin/activate

By using pip you can then install your packages.

pip install Django

And then start your Django project.

Solution 5:

In Django 1.10.6 I had the same error ("no module named..."). The solution that worked for me is changing "polls.apps.PollsConfig" for "mysite.polls" in settings.py. o.O

Post a Comment for "Django - Importerror: No Module Named Apps"