pdfmux icon indicating copy to clipboard operation
pdfmux copied to clipboard

AttributeError: 'RapidOCR' object has no attribute 'text_detector'

Open BwRy opened this issue 6 months ago • 1 comments

What happened?

pdfmux analyze ./test.pdf ╭───────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────────────────────╮ │ /path/to/anaconda3/envs/some_env/lib/python3.12/site-packages/pdfmux/cli.py:919 in analyze │ │ │ │ 916 │ from pdfmux.detect import classify │ │ 917 │ │ │ 918 │ classification = classify(input_path) │ │ ❱ 919 │ audit = audit_document(input_path) │ │ 920 │ │ │ 921 │ console.print(f"\n[bold]{input_path.name}[/bold] — {classification.page_count} pages\n") │ │ 922 │ │ │ │ /path/to/anaconda3/envs/some_env/lib/python3.12/site-packages/pdfmux/audit.py:265 in audit_document │ │ │ │ 262 │ │ end = min(start + PAGE_WINDOW, total_pages) │ │ 263 │ │ page_range = list(range(start, end)) │ │ 264 │ │ │ │ ❱ 265 │ │ chunks = pymupdf4llm.to_markdown(str(file_path), page_chunks=True, pages=page_range) │ │ 266 │ │ │ │ 267 │ │ # Reuse cached doc for heading detection │ │ 268 │ │ try: │ │ │ │ /path/to/anaconda3/envs/some_env/lib/python3.12/site-packages/pymupdf4llm/init.py:191 in to_markdown │ │ │ │ 188 │ │ 189 def to_markdown(*args, **kwargs): │ │ 190 │ if _use_layout: │ │ ❱ 191 │ │ return _layout_to_markdown(*args, **kwargs) │ │ 192 │ else: │ │ 193 │ │ return pymupdf4llm.helpers.pymupdf_rag.to_markdown(*args, **kwargs) │ │ 194 │ │ │ │ /path/to/anaconda3/envs/some_env/lib/python3.12/site-packages/pymupdf4llm/init.py:80 in _layout_to_markdown │ │ │ │ 77 │ ): │ │ 78 │ if write_images and embed_images: │ │ 79 │ │ raise ValueError("Cannot both write_images and embed_images") │ │ ❱ 80 │ parsed_doc = pymupdf4llm.helpers.document_layout.parse_document( │ │ 81 │ │ │ doc, │ │ 82 │ │ │ filename=filename, │ │ 83 │ │ │ image_dpi=dpi, │ │ │ │ /path/to/anaconda3/envs/some_env/lib/python3.12/site-packages/pymupdf4llm/helpers/document_layout.py:1083 in parse_document │ │ │ │ 1080 │ │ │ │ keep_ocr_text = True │ │ 1081 │ │ │ else: │ │ 1082 │ │ │ │ keep_ocr_text = False │ │ ❱ 1083 │ │ │ ocr_function( │ │ 1084 │ │ │ │ page, dpi=ocr_dpi, language=ocr_language, keep_ocr_text=keep_ocr_text │ │ 1085 │ │ │ ) │ │ 1086 │ │ │ page_full_ocred = True │ │ │ │ /path/to/anaconda3/envs/some_env/lib/python3.12/site-packages/pymupdf4llm/ocr/rapidtess_api.py:189 in exec_ocr │ │ │ │ 186 │ matrix = pymupdf.Rect(pixmap.irect).torect(page.rect) │ │ 187 │ # t0 = time.perf_counter() │ │ 188 │ # Execute the ENGINE's bbox Detector │ │ ❱ 189 │ boxes, _ = ENGINE.text_detector(img) │ │ 190 │ # t1 = time.perf_counter() │ │ 191 │ # Execute Tesseract's text Recognizer │ │ 192 │ # List of Tesseract text results │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ AttributeError: 'RapidOCR' object has no attribute 'text_detector'

Expected behavior

I expected the pdfmux to analyze a pdf, it yielding a per-page confidence score analysis.

Steps to reproduce

  1. pip install pdfmux[tables,ocr,llm-ollama,opendataloader,rapidocr]
  2. pdfmux analyze ./file.pdf
  3. See error

Environment (pdfmux doctor)

$ pdfmux doctor

pdfmux 1.6.4
Python 3.12.13

┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Extractor       ┃ Status       ┃ Version    ┃ Install                       ┃
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ PyMuPDF         │ ✓ installed  │ 1.27.2.3   │                               │
│ pymupdf4llm     │ ✓ installed  │ 1.27.2.3   │                               │
│ OpenDataLoader  │ ✓ installed  │ —          │                               │
│ Docling         │ ✓ installed  │ —          │                               │
│ RapidOCR        │ ✗ missing    │ —          │ pip install pdfmux[ocr]       │
│ Surya OCR       │ ✗ missing    │ —          │ pip install pdfmux[ocr-heavy] │
│ Marker          │ ✗ missing    │ —          │ pip install pdfmux[marker]    │
│ Mistral OCR SDK │ ✓ installed  │ —          │                               │
│ Gemini Flash    │ ✓ installed  │ 1.75.0     │                               │
└─────────────────┴──────────────┴────────────┴───────────────────────────────┘

LLM Providers
┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Provider   ┃ SDK          ┃ API Key      ┃ Default Model               ┃ Install                        ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ gemini     │ ✓            │ ✓            │ gemini-2.5-flash            │                                │
│ gemma      │ ✓            │ ✓            │ gemma-3-27b-it              │                                │
│ claude     │ ✓            │ ✗            │ claude-sonnet-4-6-20250514  │ pip install pdfmux[llm-claude] │
│ openai     │ ✓            │ ✓            │ gpt-4o                      │                                │
│ ollama     │ ✓            │ ✗            │ (requires PDFMUX_LLM_MODEL) │ pip install pdfmux[llm-ollama] │
└────────────┴──────────────┴──────────────┴─────────────────────────────┴────────────────────────────────┘

Coverage by Document Type
  Digital text    ███████████████████░  95%  (pymupdf)
  Scanned docs    █████████████████░░░  88%  (llm)
  Tables          █████████████████░░░  85%  (llm) → add mistral_ocr for 94%
  Image-heavy     ████████████████░░░░  82%  (llm)
  Mixed content   █████████████████░░░  85%  (llm)
  Handwriting     ████████████████░░░░  80%  (llm)
  Forms           █████████████████░░░  85%  (llm)

Recommendations
  ⚡ Add mistral_ocr for +9% better tables extraction
     pip install pdfmux

Overall readiness: 85%

pdfmux version

1.6.4

Python version

3.12.13

Operating system

Linux

Sample PDF

No response

BwRy avatar May 22 '26 15:05 BwRy

Investigated this today, building the reproduction venv exactly the way pip install resolves it rather than an ad-hoc local venv (a mistake I made and corrected in a prior pass on this same issue — see the ledger note at products/pdfmux/pipeline/LEDGER.md tick 38/39 if useful).

Root cause, confirmed: your pdfmux doctor output shows pymupdf4llm 1.27.2.3 on pdfmux 1.6.4. At that time pyproject.toml pinned pymupdf4llm>=0.0.10 with no upper bound, so pip resolved the newest available pymupdf4llm — a version that routes through its own internal layout/OCR engine (helpers/document_layout.py), where the bundled OCR glue calls ENGINE.text_detector(...), an attribute the current rapidocr package renamed to text_det. That's the exact crash in your traceback.

This was already fixed, incidentally, before you filed it stayed open: PR #21 (6cf81482, 2026-07-20) pinned pymupdf4llm<1.0 for an unrelated reason (1.28.0 was found to silently drop body text). That pin resolves pymupdf4llm to 0.3.4 on every install since — and 0.3.4's code (helpers/pymupdf_rag.py) has no RapidOCR/OCR-dispatch code at all (grepped the actual installed file, zero hits for rapidocr/text_detector/OCR-dispatch). Today's PyPI pdfmux==1.8.7 still carries that pin (pymupdf4llm<1.0,>=0.0.10, confirmed via pypi.org/pypi/pdfmux/1.8.7/json).

Verified end-to-end, not just by reading code: fresh python3 -m venv + pip install "pdfmux[ocr]" (today, from PyPI — no local repo involved) resolves pymupdf4llm==0.3.4 and rapidocr==3.10.0, and running pdfmux analyze against a scanned (image-only) page correctly falls through to pdfmux's own RapidOCR integration and completes cleanly — no AttributeError, no crash.

Could you confirm on your end?

pip install --upgrade pdfmux
pdfmux doctor   # check the pymupdf4llm line reads 0.3.4
pdfmux analyze ./your-file.pdf

If it still crashes on current pdfmux, that'd mean something is overriding the pin in your environment (e.g. a conda channel installing pymupdf4llm outside pip's resolver) and I'd like to see the new traceback + pdfmux doctor output. Leaving this open until you've had a chance to check — not closing on my own confirmation alone.

NameetP avatar Oct 17 '26 02:10 NameetP