{"id":"4d0c9a9e2198e071","repo":"celery/celery","slug":"error-module-module-doesn-t-exist-or-it-s-no","errorCode":null,"errorMessage":"Error: Module '{module}' doesn't exist, or it's not a valid Python module name.\n","messagePattern":"Error: Module '(.+?)' doesn't exist, or it's not a valid Python module name\\.\n","errorType":"exception","errorClass":"NotAPackage","httpStatus":null,"severity":"error","filePath":"celery/loaders/base.py","lineNumber":154,"sourceCode":"            # here (e.g., ``os.path:abspath``).\n            return symbol_by_name(path, imp=imp)\n\n        # Not sure if path is just a module name or if it includes an\n        # attribute name (e.g., ``os.path``, vs, ``os.path.abspath``).\n        try:\n            return imp(path)\n        except ImportError:\n            # Not a module name, so try module + attribute.\n            return symbol_by_name(path, imp=imp)\n\n    def _import_config_module(self, name):\n        try:\n            self.find_module(name)\n        except NotAPackage as exc:\n            if name.endswith('.py'):\n                reraise(NotAPackage, NotAPackage(CONFIG_WITH_SUFFIX.format(\n                        module=name, suggest=name[:-3])), sys.exc_info()[2])\n            raise NotAPackage(CONFIG_INVALID_NAME.format(module=name)) from exc\n        else:\n            return self.import_from_cwd(name)\n\n    def find_module(self, module):\n        return find_module(module)\n\n    def cmdline_config_parser(self, args, namespace='celery',\n                              re_type=re.compile(r'\\((\\w+)\\)'),\n                              extra_types=None,\n                              override_types=None):\n        extra_types = extra_types if extra_types else {'json': json.loads}\n        override_types = override_types if override_types else {\n            'tuple': 'json',\n            'list': 'json',\n            'dict': 'json'\n        }\n        from celery.app.defaults import NAMESPACES, Option\n        namespace = namespace and namespace.lower()","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/celery/celery/blob/571efe81202341310b6257304980ba7898ab0f60/celery/loaders/base.py#L136-L172","documentation":"BaseLoader._import_config_module calls find_module(name); if it raises NotAPackage (the path is not a valid importable package/module), the loader raises NotAPackage with a message that the module doesn't exist or isn't a valid name. If the name ends in '.py', it additionally suggests the suffix-stripped name, since users commonly include the extension.","triggerScenarios":"Setting CELERY_CONFIG_MODULE to a module that doesn't exist on sys.path; including a `.py` extension in the module name; giving a path with invalid characters for a Python module.","commonSituations":"Wrong CELERY_CONFIG_MODULE value; config module not on PYTHONPATH; typo; including file extension like `myconfig.py`; running from a different working directory.","solutions":["Verify the module is importable: `python -c \"import myconfig\"` from the worker's cwd","Remove any `.py` suffix from CELERY_CONFIG_MODULE (use `myconfig`, not `myconfig.py`)","Ensure the directory containing the config module is on PYTHONPATH or is the cwd","Check for typos in the module path"],"exampleFix":"// before\nexport CELERY_CONFIG_MODULE=myconfig.py  # NotAPackage\n\n// after\nexport CELERY_CONFIG_MODULE=myconfig","handlingStrategy":"validation","validationCode":"import os, importlib\nname = os.environ.get('CELERY_CONFIG_MODULE')\nif name:\n    name = name[:-3] if name.endswith('.py') else name\n    try:\n        importlib.import_module(name)\n    except ImportError as e:\n        raise SystemExit(f'CELERY_CONFIG_MODULE {name!r} is not importable: {e}')","typeGuard":null,"tryCatchPattern":"from celery.utils.imports import NotAPackage\ntry:\n    app.loader._import_config_module(name)\nexcept NotAPackage as e:\n    if name.endswith('.py'):\n        os.environ['CELERY_CONFIG_MODULE'] = name[:-3]\n    raise","preventionTips":["Never include the .py suffix in CELERY_CONFIG_MODULE","Ensure the config module is on PYTHONPATH / is importable from cwd","Validate the config module import in a startup check"],"tags":["configuration","loader","import","settings"],"analyzedSha":"571efe81202341310b6257304980ba7898ab0f60","analyzedAt":"2026-08-04T20:17:20.567Z","schemaVersion":2}