OpenBB-finance/OpenBB · error · FileNotFoundError
Error: Neither module '{module_path}' could be imported nor
Error message
Error: Neither module '{module_path}' could be imported nor file '{file_path}' exists What it means
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.
Source
Thrown at openbb_platform/extensions/platform_api/openbb_platform_api/utils/api.py:259
spec.loader.exec_module(module) # type: ignore
return module
if _is_module_colon_notation(app_path):
module_path, name = app_path.rsplit(":", 1)
try: # First try to import as a module
module = import_module(module_path)
except ImportError: # If module import fails, try to load as a local file
if not module_path.endswith(".py"):
module_path += ".py"
if not Path(module_path).is_absolute():
cwd = Path.cwd()
file_path = str(cwd.joinpath(module_path).resolve())
else:
file_path = module_path
if not Path(file_path).exists():
raise FileNotFoundError( # pylint: disable=raise-missing-from
f"Error: Neither module '{module_path}' could be imported nor file '{file_path}' exists"
)
module = _load_module_from_file_path(file_path)
# Case 2: File path (e.g., "main.py" or "my_app/main.py")
else:
if not Path(app_path).is_absolute():
cwd = Path.cwd()
app_path = str(cwd.joinpath(app_path).resolve())
if not Path(app_path).exists():
raise FileNotFoundError(f"Error: The app file '{app_path}' does not exist")
module = _load_module_from_file_path(app_path)
if not hasattr(module, name):
raise AttributeError(View on GitHub (pinned to 3e071fcc2c)
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.
Example fix
# before
# running from ~/ with app living in /proj
uvicorn-style import_app('myapp.main:app', 'app')
# after
cd /proj && import_app('myapp.main:app', 'app')
# or: import_app('/proj/myapp/main.py', 'app') Defensive patterns
Strategy: validation
Validate before calling
from importlib.util import find_spec
from pathlib import Path
ok = find_spec(module_path) is not None or Path(f"{module_path}.py").is_file()
assert ok, f"{module_path} is neither importable nor a local file" Type guard
def module_resolves(module_path: str) -> bool:
from importlib.util import find_spec
try:
return find_spec(module_path) is not None
except (ImportError, ValueError):
return False Try / catch
try:
app = import_app("myapp.main:app", "app")
except FileNotFoundError as e:
print(e) # lists both attempted paths; fix cwd or install package
raise Prevention
- Install your app package with pip install -e .
- Launch from the project root
- Prefer absolute file paths in scripts
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to load the file specs for '{file_path}'
- Error: The app file '{app_path}' does not exist
- Error: Neither module '{module_path}' could be imported nor
- Error: The app file '{app_path}' does not contain an '{name}
- Error: The {name} instance in '{app_path}' appears not to be
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/22284f335ea2e6a6.
Report an issue: GitHub.