ilikethestars
ilikethestars

Reputation: 145

Django ModuleNotFoundError

I can't make a simple Django project work at all. I get the same error as listed in this question which I found:

Python/Django =- ModuleNotFoundError: No module named 'restaurants'

The only difference for me is that it says "No module named entries". This doesn't seem to have a resolution and I don't understand the comment on it either.

My directory structure is like this:

app
|- manage.py
|- app
    |- __init__.py
    |- entries
    |    |- __init__.py
    |    |- apps.py 
    |    |- models.py
    |    |- views.py
    |    |- admin.py
    |    |- tests.py
    |    |- migrations - __init__.py
    |    
    |- urls.py
    |- settings.py
    |- __pycache__
    |- wsgi.py

I have added the entries app to the INSTALLED_APPS list in settings.py. But from there it just seems to run into a problem.

I have been trying to work this out for ages and I just don't get it (even though it is probably easy).

UPDATE This is the exact stacktrace I am getting:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/maximus/.virtualenvs/piglet/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/Users/maximus/.virtualenvs/piglet/lib/python3.6/site-packages/django/core/management/__init__.py", line 338, in execute
    django.setup()
  File "/Users/maximus/.virtualenvs/piglet/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/maximus/.virtualenvs/piglet/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Users/maximus/.virtualenvs/piglet/lib/python3.6/site-packages/django/apps/config.py", line 94, in create
    module = import_module(entry)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'entries' 

Update 2: This is my INSTALLED_APPS:

INSTALLED_APPS = [
    'rest_framework',
    'entries.apps.EntriesConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

I have tried using just entries as well. Which gives the same error.

Upvotes: 14

Views: 63348

Answers (7)

Isaac Agyei Annor
Isaac Agyei Annor

Reputation: 21

I had a similar error and I resolved that by moving the Django app folder into the Django project directory before I was able to run python manage.py runserver with no errors.

Upvotes: 1

Pfinnn
Pfinnn

Reputation: 572

In my case it was the simplest mistake, which is often the hardest to see: I missed the comma separation between the new app I wanted to add in the INSTALLED_APPS. Dont be me, double check your spelling.

Upvotes: 0

Sidrah Madiha Siddiqui
Sidrah Madiha Siddiqui

Reputation: 1364

you should add the app in INSTALLED_APPS like so: 'app.entries'

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'app.entries',
    'rest_framework', ]

Upvotes: 5

Orkhan Shirin
Orkhan Shirin

Reputation: 59

if you started a project using django-admin startproject <project's name> on terminal, then try not to change PROJECT_DIR and BASE_DIR. They should be same.

Upvotes: 4

iffishells
iffishells

Reputation: 9

its seems to be error which i faced during this django jounrney you have to do here manage.py and firstproject whatever the name at the same direcotry then add new "fist_App" in the setting.py at installed_App list then check the python manage.py fristapp

Upvotes: -3

Sumit Khedkar
Sumit Khedkar

Reputation: 75

In your case the INSTALLED_APPS should be INSTALLED_APPS = [ 'rest_framework', 'app.entries.apps.EntriesConfig', ....... ]

Also in entries/apps.py file in fEntriesConfig() set name = 'app.entries'

Upvotes: 0

Mark Chackerian
Mark Chackerian

Reputation: 23512

It looks like your entries directory is in the wrong place. You should move it up one level, so it's app/entries instead of app/app/entries.

(You are correct that 'entries.apps.EntriesConfig' is a valid way to add to INSTALLED_APPS.)

Upvotes: 10

Related Questions