PaddlePaddle/PaddleOCR · error · FileNotFoundError
{destination}
Error message
{destination} What it means
Builtin FileNotFoundError raised by _require_existing_directory when the destination passed to save_ocr_result_resources / save_document_parsing_result_resources does not exist on disk. Unlike save_resource, the batch helpers require destination to be an existing directory and never create it.
Source
Thrown at paddleocr/_api_client/_resources.py:145
_validate_result_resource_filename(filename)
target = destination_path / filename
elif destination_path.exists() and destination_path.is_dir():
target = destination_path / _safe_url_basename(url_path)
else:
target = destination_path
parent = target.parent
if not parent.exists():
raise FileNotFoundError(str(parent))
if not parent.is_dir():
raise InvalidRequestError(f"Destination parent must be a directory: {parent}")
return target
def _require_existing_directory(destination: str) -> Path:
dest_dir = Path(destination)
if not dest_dir.exists():
raise FileNotFoundError(destination)
if not dest_dir.is_dir():
raise InvalidRequestError(
f"Destination must be an existing directory: {destination}"
)
return dest_dir
def _require_writable_target(target: Path, overwrite: bool) -> None:
if target.exists() and not overwrite:
raise InvalidRequestError(f"Destination already exists: {target}")
def _atomic_write(target: Path, content: bytes, overwrite: bool) -> None:
fd, temp_path = tempfile.mkstemp(
prefix=f".{target.name}.tmp-",
dir=str(target.parent),
)
try:View on GitHub (pinned to 2661c7c0ef)
Solutions
- Create the directory before the call: Path(dest).mkdir(parents=True, exist_ok=True)
- Verify the path against the actual mount layout in the failing environment (container volume, network share)
- Add a startup check that creates/validates configured output directories once, not per-file
Example fix
# before
save_ocr_result_resources(result, '/data/out') # dir missing
# after
from pathlib import Path
Path('/data/out').mkdir(parents=True, exist_ok=True)
save_ocr_result_resources(result, '/data/out') Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path Path(destination).mkdir(parents=True, exist_ok=True) assert Path(destination).is_dir()
Try / catch
try:
save_ocr_result_resources(result, dest_dir)
except FileNotFoundError as e:
Path(str(e)).mkdir(parents=True, exist_ok=True)
save_ocr_result_resources(result, dest_dir) Prevention
- Pre-create output directories once at startup
- The batch helpers never create directories — treat that as a contract
When it happens
Trigger: save_ocr_result_resources(result, '/data/out') with /data/out absent; output directory referenced in config but never created in this environment/deployment.
Common situations: Fresh clone/container where the output dir is expected to pre-exist; CI runs with a workspace that lacks the artifacts dir; directory name typo; the dir exists on the dev machine but not in production mount layout.
Related errors
- {parent}
- Destination must be an existing directory: {destination}
- Destination already exists: {target}
- Unsafe resource filename: ${key}
- File not found: ${path}
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/c1de20786c58e889.
Report an issue: GitHub.