Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'xxxdjango'

I've been looking thoroughly before asking this question but couldn't find the answer on Stack Overflow. ModuleNotFoundError: No module named 'firstappdjango' has a similar error but does not solve my problem.

I've launched default app without problems and got Django screen etc. I am following a tutorial now and I started simple app with some HTML response. I get error called ModuleNotFoundError: No module named 'adamprojectdjango' when I want to run server.

What I've checked/some info

  • my app is called adamproject

  • app installed in settings.py

    INSTALLED_APPS = [
        'adamproject'
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
    ]
    
  • directories look as below

       /home/none/eclipse-workspace/test5
        ├── adamproject
        │   └── migrations
        └── test5
        └── __pycache__
    
  • app config file:

    from django.apps import AppConfig
    class MysiteConfig(AppConfig):
        name = 'adamproject'
    
like image 428
Adam Avatar asked Nov 15 '18 16:11

Adam


People also ask

How do I fix modulenotfounderror - no module named Django?

The ModuleNotFoundError: No module named ‘django’ error occurs when we try to import the ‘ Django ‘ module without installing the package or if you have not installed it in the correct environment. We can resolve the issue by installing the Django module by running the pip install Django command.

What does no module named Mean in Python?

One common cause of the ModuleNotFoundError: No module named error is simply that the module you're trying to import doesn't exist. This can happen if you've misspelled the module name, or if you're trying to import a module that's not in your Python path.

Why am I getting a module name error when importing it?

The first reason of this error is the name of the module is incorrect, so you have to check out the module name that you had imported. For example, let's try to import os module with double s and see what will happen:

How to get Django module name in Python?

Apparently, there is no module with the name of ‘django’. So,check it first by listing all of the available module in the current python environment by typing the following command :


1 Answers

Consider the following:

my_string = 'adamproject' 'django.contrib.admin'
print(my_string)
# prints:
# adamprojectdjango.contrib.admin

You have a missing comma after 'adamproject'. So it is being concatenated to what you intended to be the subsequent list entry. This results in an attempt to load an app from the module adamprojectdjango which does not exist.

INSTALLED_APPS = [
    'adamproject'
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

print(INSTALLED_APPS)
# prints:
# ['adamprojectdjango.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles']

Instead, your list of INSTALLED_APPS should be declared like this:

INSTALLED_APPS = [
    'adamproject',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
like image 146
Rob Bricheno Avatar answered Oct 29 '22 03:10

Rob Bricheno