ModuleNotFoundError: No module named 'blog'

Hey, I’ve just started coding with Django with a tutorial from an german YouTuber:

(here the vid to rebuild my error)

I just set up my Django Server wich was running correctly and after that I created the Modules blog and web. Since that step the Server/Site wont run anymore.

The Terminal in PyCharm:

(venv) C:\Users\Finn\PycharmProjects\tutorial\webseite>python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File “C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\threading.py”, line 954, in _bootstrap_inner
self.run()
File “C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\threading.py”, line 892, in run
self._target(*self.args, **self.kwargs)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 53, in wrapper
fn(*args, **kwargs)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\commands\runserver.py”, line 110, in inner_run
autoreload.raise_last_exception()
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 76, in raise_last_exception
raise exception[1]
File "C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management_init
.py", line 357, in execute
autoreload.check_errors(django.setup)()
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django_init
.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\apps\registry.py”, line 91, in populate
app_config = AppConfig.create(entry)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\apps\config.py”, line 116, in create
mod = import_module(mod_path)
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\importlib_init
.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1030, in _gcd_import
File “”, line 1007, in _find_and_load
File “”, line 972, in _find_and_load_unlocked
File “”, line 228, in _call_with_frames_removed
File “”, line 1030, in _gcd_import
File “”, line 1007, in find_and_load
File “”, line 984, in find_and_load_unlocked
ModuleNotFoundError: No module named ‘blog’
Traceback (most recent call last):
File “C:\Users\Finn\PycharmProjects\tutorial\webseite\manage.py”, line 22, in
main()
File “C:\Users\Finn\PycharmProjects\tutorial\webseite\manage.py”, line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management_init
.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management_init
.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\base.py”, line 330, in run_from_argv
self.execute(*args, **cmd_options)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\commands\runserver.py”, line 61, in execute
super().execute(*args, **options)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\base.py”, line 371, in execute
output = self.handle(*args, **options)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\commands\runserver.py”, line 96, in handle
self.run(**options)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\commands\runserver.py”, line 103, in run
autoreload.run_with_reloader(self.inner_run, **options)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 618, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 603, in start_django
reloader.run(django_main_thread)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 318, in run
self.run_loop()
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 324, in run_loop
next(ticker)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 364, in tick
for filepath, mtime in self.snapshot_files():
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 380, in snapshot_files
for file in self.watched_files():
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 278, in watched_files
yield from iter_all_python_module_files()
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 105, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\autoreload.py”, line 141, in iter_modules_and_files
resolved_path = path.resolve(strict=True).absolute()
File “C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\pathlib.py”, line 1204, in resolve
s = self._flavour.resolve(self, strict=strict)
File “C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\pathlib.py”, line 200, in resolve
return self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 123] Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch: ‘’

(venv) C:\Users\Finn\PycharmProjects\tutorial\webseite>python manage.py runserver
Traceback (most recent call last):
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\base.py”, line 330, in run_from_argv
self.execute(*args, **cmd_options)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\commands\runserver.py”, line 61, in execute
super().execute(*args, **options)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\base.py”, line 371, in execute
output = self.handle(*args, **options)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\commands\runserver.py”, line 68, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\conf_init_.py”, line 82, in getattr
self.setup(name)
File "C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\conf_init
.py", line 69, in setup
self.wrapped = Settings(settings_module)
File "C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\conf_init
.py", line 170, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\importlib_init
.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1030, in _gcd_import
File “”, line 1007, in _find_and_load
File “”, line 986, in _find_and_load_unlocked
File “”, line 680, in _load_unlocked
File “”, line 790, in exec_module
File “”, line 228, in _call_with_frames_removed
File “C:\Users\Finn\PycharmProjects\tutorial\webseite\webseite\settings.py”, line 14, in
from blog.models import Blog
ModuleNotFoundError: No module named ‘blog’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\Finn\PycharmProjects\tutorial\webseite\manage.py”, line 22, in
main()
File “C:\Users\Finn\PycharmProjects\tutorial\webseite\manage.py”, line 18, in main
execute_from_command_line(sys.argv)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management_init_.py”, line 401, in execute_from_command_line
utility.execute()
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management_init_.py”, line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\core\management\base.py”, line 343, in run_from_argv
connections.close_all()
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\db\utils.py”, line 232, in close_all
for alias in self:
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\db\utils.py”, line 226, in iter
return iter(self.databases)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\utils\functional.py”, line 48, in get
res = instance.dict[self.name] = self.func(instance)
File “C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\db\utils.py”, line 153, in databases
self.databases = settings.DATABASES
File "C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\conf_init
.py", line 82, in getattr
self.setup(name)
File "C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\conf_init
.py", line 69, in setup
self.wrapped = Settings(settings_module)
File "C:\Users\Finn\PycharmProjects\tutorial\venv\lib\site-packages\django\conf_init
.py", line 170, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\importlib_init
.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1030, in _gcd_import
File “”, line 1007, in _find_and_load
File “”, line 986, in _find_and_load_unlocked
File “”, line 680, in _load_unlocked
File “”, line 790, in exec_module
File “”, line 228, in _call_with_frames_removed
File “C:\Users\Finn\PycharmProjects\tutorial\webseite\webseite\settings.py”, line 14, in
from blog.models import Blog
ModuleNotFoundError: No module named ‘blog’

Code in the urls.py:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path(‘admin/’, admin.site.urls),
path(‘blog/’, include(‘blog.urls’)),
path(’’, include(‘web.urls’)),
]

Did you add blog to your INSTALLED_APPS in settings.py?

Where in your directory structure is your blog directory? What are the contents of that directory?

What is your BASE_DIR setting?

What version of Django are you using?

Also, when you post code snippets, directory listings, traceback messages, html - pretty much anything, please insert them between lines containing only 3 backticks - ```. (Make sure you use the backtick - ` and not the apostrophe - '.) That means you would have one line with the 3 backticks, your code, and then one more line with just the 3 backticks. That allows this forum software to format your code nicely and to not try to interpret some characters as special formatting characters.

# The line above this is just ```
def function(parm):
    return parm
# The line after this is just ```
"""
Django settings for webseite project.

Generated by 'django-admin startproject' using Django 3.1.6.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'wna%#cq!5iah2g*2z+wgu68$-7e&qmcx_u2@avtk)y#+t$by5t'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

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

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'webseite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'webseite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'de-de'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

Thats my settings.py

And I’m using the newest version of Django

Thanks for your help I found the misstake by myself. I just put the file in the wrong directory!

Hi,
Can you tell me what was the problem? I am facing something similar.

I had faced the same problem and it was because I messed up with the app name. I tried to change the app name but I forgot to change it in the INSTALLED_APPS list.

I had the same issue.

I changed the apps folder name. After changing all imports and settings.py the “no module named” still appearing.

After a while I realized that inside myapp/migrations were 2 files besides “init.py”
I deleted them, erased my sqlite database and run makemigrations and migrate again.

Problem Solved