PaddlePaddle/PaddleOCR · error · FileNotFoundError
File not found: {file_path}
Error message
File not found: {file_path} What it means
FileNotFoundError raised by doc2md_convert when the source path does not exist on disk. The function converts the input to a Path and checks existence before selecting a converter, failing fast with the resolved path in the message.
Source
Thrown at paddleocr/_doc2md/core.py:49
Convert an office document to Markdown.
Args:
source: Path to the source file.
output: Optional output file path. If provided, Markdown is written there.
**kwargs: Extra arguments forwarded to the specific converter.
Returns:
ConvertResult object.
Examples:
>>> from paddleocr import doc2md_convert
>>> result = doc2md_convert("report.docx")
>>> print(result.markdown)
"""
file_path = Path(source)
if not file_path.exists():
raise FileNotFoundError(f"File not found: {file_path}")
converter = default_registry.get_converter(file_path)
try:
result = converter.convert_file(file_path, **kwargs)
except Exception as e:
if isinstance(e, (FileNotFoundError, ValueError, RuntimeError)):
raise
raise RuntimeError(f"Failed to convert {file_path.name}: {e}") from e
if output:
output_path = Path(output)
output_path.parent.mkdir(parents=True, exist_ok=True)
output_path.write_text(result.markdown, encoding="utf-8")
if result.images:
images_dir = output_path.parent / "images"
images_dir.mkdir(exist_ok=True)
for rel_path, img_bytes in result.images.items():View on GitHub (pinned to 2661c7c0ef)
Solutions
- Verify the path exists before calling: Path(source).is_file()
- Use absolute paths built from a known base directory
- Check cwd if using relative paths: print(Path(source).resolve())
Example fix
# before
result = doc2md_convert(user_supplied_path)
# after
src = Path(user_supplied_path).resolve()
if not src.is_file():
raise FileNotFoundError(src)
result = doc2md_convert(src) Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
src = Path(source).expanduser().resolve()
if not src.is_file():
raise FileNotFoundError(f'no such file: {src}') Try / catch
try:
result = doc2md_convert(src)
except FileNotFoundError as e:
log.warning('input missing: %s', e)
skip_or_prompt_user() Prevention
- Always resolve() user-supplied paths before use
- Validate existence at request intake, not deep in the pipeline
- Handle ~ with expanduser() for CLI inputs
When it happens
Trigger: doc2md_convert('report.docx') where report.docx is not in the current working directory; passing a relative path when the process runs from another directory; typo'd or user-supplied filenames.
Common situations: Web uploads where the temp file was cleaned up or the path is outside the sandbox; CLI tools run from a different cwd; relative paths in scheduled jobs.
Related errors
- File not found: ${path}
- destination is required.
- Destination parent must be a directory: {parent}
- Destination must be an existing directory: {destination}
- Unsupported format: .{ext}\nSupported formats: {supported}
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/cce2d1371b08baff.
Report an issue: GitHub.