PaddlePaddle/PaddleOCR · error · FileNotFoundError
{parent}
Error message
{parent} What it means
Python builtin FileNotFoundError raised by _resolve_destination when the parent directory of the computed target path does not exist. Target = destination/filename, or destination/url-basename when destination is an existing directory, or destination itself otherwise; the check then requires target.parent to exist.
Source
Thrown at paddleocr/_api_client/_resources.py:136
)
return saved_paths
def _resolve_destination(
url_path: str, destination: str, filename: Optional[str]
) -> Path:
destination_path = Path(destination)
if filename is not None:
_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:View on GitHub (pinned to 2661c7c0ef)
Solutions
- Create the directory first: Path(destination).parent.mkdir(parents=True, exist_ok=True) (or the output dir itself when saving multiple files)
- Verify the destination path spelling and that mounts exist in the current environment
- If filename may contain subpaths, create target.parent, not just the destination dir
Example fix
# before
save_resource(url, '/out/pages/page-1.png') # /out/pages missing
# after
from pathlib import Path
Path('/out/pages').mkdir(parents=True, exist_ok=True)
save_resource(url, '/out/pages/page-1.png') Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path Path(destination).expanduser().parent.mkdir(parents=True, exist_ok=True) assert Path(destination).parent.is_dir()
Try / catch
try:
save_resource(url, dest)
except FileNotFoundError as e:
Path(str(e)).mkdir(parents=True, exist_ok=True) # message is the missing dir
save_resource(url, dest) Prevention
- Create output directories at pipeline start (mkdir parents=True), not per file
- Validate output roots against actual mounts in containers before running
When it happens
Trigger: save_resource(url, '/missing/dir/out.png') — the /missing/dir does not exist; or destination is a not-yet-created path (e.g. an output directory the caller never created) and its parent is absent; or filename contains a directory component ('sub/img.png') whose subdirectory does not exist under destination.
Common situations: Assuming save_resource creates output directories (it does not — mkdir is the caller's job); output dir path with a typo; filename passed with an uncreated subfolder; containerized runs where the mounted output path differs from what the code assumes.
Related errors
- Destination parent must be a directory: {parent}
- {destination}
- Destination already exists: {target}
- fileUrl and filePath are mutually exclusive.
- Unsafe resource filename: ${key}
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/766851c7d7c1dcc6.
Report an issue: GitHub.