google/python-fire · error · OSError
Fire was passed a filename which could not be found.
Error message
Fire was passed a filename which could not be found.
What it means
When the argument to fire.import_module contains a path separator but does not exist on disk, fire concludes it was intended as a filename and raises OSError('Fire was passed a filename which could not be found.') rather than trying it as a module name. This distinguishes 'path-like but missing' from the dotted-module case.
Source
Thrown at fire/__main__.py:107
IOError: if the file or module can not be found or imported.
Returns:
Tuple[ModuleType, str]: returns the imported module and the module name,
usually extracted from the path itself.
"""
if os.path.exists(module_or_filename):
# importlib.util.spec_from_file_location requires .py
if not module_or_filename.endswith('.py'):
try: # try as module instead
return import_from_module_name(module_or_filename)
except ImportError:
raise ValueError('Fire can only be called on .py files.')
return import_from_file_path(module_or_filename)
if os.path.sep in module_or_filename: # Use / to detect if it was a filename.
raise OSError('Fire was passed a filename which could not be found.')
return import_from_module_name(module_or_filename) # Assume it's a module.
def main(args):
"""Entrypoint for fire when invoked as a module with python -m fire."""
if len(args) < 2:
print(cli_string)
sys.exit(1)
module_or_filename = args[1]
module, module_name = import_module(module_or_filename)
fire.Fire(module, name=module_name, command=args[2:])
if __name__ == '__main__':View on GitHub (pinned to 716bbc23d7)
Solutions
- Check the path exists: `ls dir/subdir/mod.py`.
- Run the command from the correct working directory, or use an absolute path.
- If you meant a module, use dots not slashes: `python -m fire pkg.mod`.
Example fix
// before python -m fire src/modle.py serve # typo // after python -m fire src/model.py serve
Defensive patterns
Strategy: validation
Validate before calling
import os
arg = 'src/model.py'
if os.path.sep in arg and not os.path.exists(arg):
raise SystemExit(f'File not found: {os.path.abspath(arg)}') Type guard
def is_existing_pathlike_target(arg: str) -> bool:
return os.path.sep not in arg or os.path.exists(arg) Try / catch
try:
module, name = fire_import.import_module(arg)
except OSError as e:
print(f'{e} — check cwd and spelling of {arg}'); sys.exit(2) Prevention
- Launch CLI commands from the project root; set cd in scripts/CI.
- Use absolute paths in cron/containers.
- Use dots (pkg.mod) for modules; slashes only for real files.
When it happens
Trigger: python -m fire dir/subdir/mod (or any string containing /) where dir/subdir/mod does not exist relative to the cwd — a typo in the directory, a moved file, or running from the wrong directory.
Common situations: Running the CLI from a different cwd than the project root (CI, containers, cron); refactoring that renamed or moved files without updating the command; Windows/Unix path separator mixups.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Given file path does not exist.
- Unable to load module from specified path.
- Fire can only be called on .py files.
- FindExecutableOnPath({0},...) failed because first argument
- The command argument must be a string or a sequence of argum
AI-assisted analysis of google/python-fire@716bbc23d7 (2026-08-28).
Data as JSON: /api/errors/b9373f0264dd47d4.
Report an issue: GitHub.