{"record":{"id":"22284f335ea2e6a6","repo":"OpenBB-finance/OpenBB","slug":"error-neither-module-module-path-could-be-imp-22284f","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/platform_api/openbb_platform_api/utils/api.py","lineNumber":259,"sourceCode":"        spec.loader.exec_module(module)  # type: ignore\n        return module\n\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":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/platform_api/openbb_platform_api/utils/api.py#L241-L277","documentation":"Raised when the app path uses module:colon notation ('pkg.module:app'), the module could not be imported, and the fallback interpretation of the module path as a local .py file also does not exist. It reports both the module import and file-resolution failures.","triggerScenarios":"Calling import_app('myapp.main:app') where 'myapp.main' is neither installed/importable nor present as ./myapp/main.py relative to the current working directory.","commonSituations":"Running the API from a different working directory than the project root; missing package installation (pip install -e . not run); misspelled module name; PYTHONPATH not including the package parent.","solutions":["Run the command from the project root so the relative .py fallback resolves.","Install the package in editable mode (pip install -e .) so import_module succeeds.","Use an explicit file path instead of module notation: --app main.py (or my_app/main.py).","Verify the module name spelling and that an __init__.py exists for packages."],"exampleFix":"# before\n# running from ~/ with app living in /proj\nuvicorn-style import_app('myapp.main:app', 'app')\n\n# after\ncd /proj && import_app('myapp.main:app', 'app')\n# or: import_app('/proj/myapp/main.py', 'app')","handlingStrategy":"validation","validationCode":"from importlib.util import find_spec\nfrom pathlib import Path\nok = find_spec(module_path) is not None or Path(f\"{module_path}.py\").is_file()\nassert ok, f\"{module_path} is neither importable nor a local file\"","typeGuard":"def module_resolves(module_path: str) -> bool:\n    from importlib.util import find_spec\n    try:\n        return find_spec(module_path) is not None\n    except (ImportError, ValueError):\n        return False","tryCatchPattern":"try:\n    app = import_app(\"myapp.main:app\", \"app\")\nexcept FileNotFoundError as e:\n    print(e)  # lists both attempted paths; fix cwd or install package\n    raise","preventionTips":["Install your app package with pip install -e .","Launch from the project root","Prefer absolute file paths in scripts"],"tags":["import","path","fastapi","startup"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}