ocrmypdf/OCRmyPDF · error · ValueError

Since you specified `--output-type none`, the output file {s

Error message

Since you specified `--output-type none`, the output file {str(self.output_file)} cannot be produced. Set the output file to `-` to suppress this message.

What it means

Raised when --output-type none is used but the output file is not '-' or os.devnull. Output type 'none' produces no output file, so naming a real output path is contradictory.

Source

Thrown at src/ocrmypdf/_options.py:471

                "--redo-ocr (or --mode redo) is not currently compatible with "
                "--deskew, --clean-final, and --remove-background"
            )
        return self

    @model_validator(mode='after')
    def validate_output_type_compatibility(self):
        """Validate output type is compatible with output file."""
        if self.output_type == 'none' and str(self.output_file) not in (
            os.devnull,
            '-',
        ):
            raise ValueError(
                "Since you specified `--output-type none`, the output file "
                f"{str(self.output_file)} cannot be produced. Set the output file to "
                f"`-` to suppress this message."
            )
        return self

    @property
    def lossless_reconstruction(self):
        """Determine lossless_reconstruction based on other options."""
        lossless = not any(
            [
                self.deskew,
                self.clean_final,
                self.mode == ProcessingMode.force,
                self.remove_background,
            ]
        )
        return lossless

    def model_dump_json_safe(self) -> str:
        """Serialize to JSON with special handling for non-serializable types."""
        # Create a copy of the model data for serialization
        data = self.model_dump()

View on GitHub (pinned to 5074a0b0e1)

Solutions

  1. Set output_file to '-' (or os.devnull) when output_type='none'
  2. Remove --output-type none if you actually want a PDF written

Example fix

# before
ocrmypdf --output-type none -l eng in.pdf out.pdf --sidecar out.txt
# after
ocrmypdf --output-type none -l eng in.pdf - --sidecar out.txt
Defensive patterns

Strategy: validation

Validate before calling

import os
if opts.output_type == 'none' and str(opts.output_file) not in (os.devnull, '-'):
    opts.output_file = '-'

Try / catch

catch ValueError and re-ask user for output destination

Prevention

When it happens

Trigger: Setting output_type='none' in OcrOptions while output_file is a real path or stream other than '-' / os.devnull; validated in OcrOptions validation during create_options/execute_ocrmypdf.

Common situations: Using --output-type none for sidecar-only or verification runs while still naming an output PDF; API users passing a file object.

Related errors


AI-assisted analysis of ocrmypdf/OCRmyPDF@5074a0b0e1 (2026-08-27). Data as JSON: /api/errors/9243705323769842. Report an issue: GitHub.