{"record":{"id":"8d41b82866734e33","repo":"OpenBB-finance/OpenBB","slug":"error-neither-module-module-path-could-be-imp","errorCode":null,"errorMessage":"Error: Neither module '{module_path}' could be imported nor file '{file_path}' exists","messagePattern":"Error: Neither module '(.+?)' could be imported nor file '(.+?)' exists","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py","lineNumber":56,"sourceCode":"        return module\n\n    # Case 1: Module path with colon notation (e.g., \"my_app.main:app\" or \"main:app\")\n    if _is_module_colon_notation(app_path):\n        module_path, name = app_path.rsplit(\":\", 1)\n        try:  # First try to import as a module\n            module = import_module(module_path)\n        except ImportError:  # If module import fails, try to load as a local file\n            if not module_path.endswith(\".py\"):\n                module_path += \".py\"\n\n            if not Path(module_path).is_absolute():\n                cwd = Path.cwd()\n                file_path = str(cwd.joinpath(module_path).resolve())\n            else:\n                file_path = module_path\n\n            if not Path(file_path).exists():\n                raise FileNotFoundError(  # pylint: disable=raise-missing-from\n                    f\"Error: Neither module '{module_path}' could be imported nor file '{file_path}' exists\"\n                )\n\n            module = _load_module_from_file_path(file_path)\n\n    # Case 2: File path (e.g., \"main.py\" or \"my_app/main.py\")\n    else:\n        if not Path(app_path).is_absolute():\n            cwd = Path.cwd()\n            app_path = str(cwd.joinpath(app_path).resolve())\n\n        if not Path(app_path).exists():\n            raise FileNotFoundError(f\"Error: The app file '{app_path}' does not exist\")\n\n        module = _load_module_from_file_path(app_path)\n\n    if not hasattr(module, name):\n        raise AttributeError(","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py#L38-L74","documentation":"FileNotFoundError raised when an app path using module:attr colon notation cannot be resolved either way: importlib failed to import 'module_path' as a Python module, and the fallback that treats it as a local file (with .py appended) does not exist on disk. The message names both the module and the resolved absolute file path that was tried.","triggerScenarios":"--app my_app.main:app where 'my_app' is not installed and no ./my_app/main.py exists relative to the CWD (relative paths are resolved against Path.cwd()). Also module typos, missing __init__.py for the intended package, or running the CLI from a directory where the source tree is absent.","commonSituations":"Running the MCP server from a different directory than the project root, forgetting to pip install -e the package that contains the app, virtualenv not activated so the module is not importable, file present but under a slightly different name than the module path implies.","solutions":["Run the command from the project root so the relative .py path resolves, or pass an absolute file path","Install the package containing the module (pip install -e .) so import_module succeeds","Double-check the module path spelling and that a matching .py file (or package with __init__.py) exists at the printed location"],"exampleFix":"# before\nopenbb-mcp --app my_app.main:app   # run from wrong cwd, package not installed\n\n# after\ncd /path/to/project && openbb-mcp --app my_app.main:app\n# or: pip install -e /path/to/project && openbb-mcp --app my_app.main:app","handlingStrategy":"validation","validationCode":"from importlib.util import find_spec\nfrom pathlib import Path\n\nmodule_path = app_path.rsplit(\":\", 1)[0]\nimportable = find_spec(module_path) is not None\nfile_exists = Path(module_path if module_path.endswith(\".py\") else module_path + \".py\").exists()\nif not (importable or file_exists):\n    raise ValueError(f\"{module_path} is neither importable nor a local file\")","typeGuard":"def app_module_resolvable(app_path: str) -> bool:\n    from importlib.util import find_spec\n    module_path = app_path.rsplit(\":\", 1)[0]\n    if find_spec(module_path) is not None:\n        return True\n    candidate = module_path if module_path.endswith(\".py\") else module_path + \".py\"\n    return Path(candidate).exists()","tryCatchPattern":"try:\n    app = import_app(\"my_app.main:app\", \"app\")\nexcept FileNotFoundError as e:\n    if \"Neither module\" in str(e):\n        # fall back to an explicit absolute file path\n        app = import_app(\"/abs/path/to/my_app/main.py:app\", \"app\")\n    else:\n        raise","preventionTips":["pip install -e . the package containing your app before launching the server","Always launch from the project root, or pass absolute paths","Verify module path spelling and that the printed fallback file path actually exists"],"tags":["python","import","cli","file-not-found","fastapi"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}