OSError: (WinError 123) The filename, directory name, or volume label syntax is incorrect

Introduction

This article will show how to solve an error message appear as OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: ”. The error itself appear after adding an application module to the project using a Django-based framework. After adding it to a file with the name of ‘settings.py’ exist in the root folder of the project and then run it, the error appear later on. The following is the part where the application module name exist in the ‘settings.py’ for a comparison.

The original configuration of the ‘settings.py’ file :

# Application definition INSTALLED_APPS = [     'django.contrib.admin',     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.messages',     'django.contrib.staticfiles', ]

After editing the original configuration of the ‘settings.py’ by adding an application module with the name of ‘myapp’ :

# Application definition INSTALLED_APPS = [     'django.contrib.admin',     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.messages',     'django.contrib.staticfiles',     'myapp' ]

Furthermore, the following is the actual process for creating a new project and a new application :

  1. Run django-admin startproject ‘project_name’. As in this example, the following is the execution of the command pattern :

    (env) C:\programming\python\django>django-admin startproject myproject (env) C:\programming\python\django>
  2. Next step, run the django-admin startapp ‘app_name’. As for the example, the following is the execution of the command pattern :

    (env) C:\programming\python\django>django-admin startapp myapp (env) C:\programming\python\django>
  3. Apparently, the following is the actual tree directory structure :

    Folder PATH listing for volume Windows Volume serial number is E003-3593 Folder PATH listing for volume Windows Volume serial number is E003-3593 C:programming\python\django | +---env +---myapp +---myproject

    For further reference about the command usage of ‘tree’ to print the content of a directory, just read the article ‘How to save the directory structure of a path in Microsoft Windows to a file’ in this link.

Solution

The actual solution for the above error is simple. The above error message appear when running a virtual server using the following command path for running the Django project :

Test (env) C:\programming\python\django\myproject>python manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "C:\Python38\lib\threading.py", line 932, in _bootstrap_inner ... ModuleNotFoundError: No module named 'myapp' Traceback (most recent call last): File "manage.py", line 22, in main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) ... OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '' (env) C:\programming\python\django\myproject>

So, the application module with the name ‘myapp’ cannot be found as in the output above. Although, the definition to add ‘myapp’ is exist in the ‘settings.py’ file as part of the project configuration setting file. Actually, the solution is very simple. The problem exist in the path of the application module with the name ‘myapp’. Just move the ‘myapp’ folder into the ‘myproject’ folder so that the directory structure will be in the following structure :

Folder PATH listing for volume Windows Volume serial number is E003-3593 Folder PATH listing for volume Windows Volume serial number is E003-3593 C:programming\python\django | +---env +---myproject | |---myapp

  • Problem which appear :-
  • Way to Solve
    • – Install the module
    • – Find the location where , you have mention this module.

Problem which appear :-

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: ‘

This error appears like below on screen in Django :

OSError: (WinError 123) The filename, directory name, or volume label syntax is incorrect

Way to Solve

This error could come on various reasons , so you have to scroll up , & check whether another error is showing on screen or not , in our case , when we scroll up , we got one more error , that some module is not found like –

OSError: (WinError 123) The filename, directory name, or volume label syntax is incorrect

This means , this module is mention some where, or used somewhere , but this module is actually not installed.

So , in this case it’s on you , you can do these two things :

–Install the module

If , you have used this module in your code, and it is necessary to use this module , than install this module , your problem will be solved.

– Find the location where , you have mention this module.

Normally, whatever module we install first mention that in settings.py in INSTALLED_APPS section.

So, go in settings.py file , and remove this module from INSTALLED_APPS section & also remove all usage of this module from the code, your problem will be solved.