From aa843e144f0728392600133724211d8c7f7d3b11 Mon Sep 17 00:00:00 2001 From: Zhang Jun Date: Wed, 6 Mar 2024 15:36:30 +0800 Subject: [PATCH] lazy import PyMuPDF --- ppocr/utils/utility.py | 3 ++- ppstructure/pdf2word/pdf2word.py | 2 ++ requirements.txt | 1 - 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ppocr/utils/utility.py b/ppocr/utils/utility.py index 47461d7d5e..91b74f022d 100755 --- a/ppocr/utils/utility.py +++ b/ppocr/utils/utility.py @@ -107,7 +107,8 @@ def check_and_read(img_path): imgvalue = frame[:, :, ::-1] return imgvalue, True, False elif os.path.basename(img_path)[-3:].lower() == 'pdf': - import fitz + from paddle.utils import try_import + try_import('fitz') from PIL import Image imgs = [] with fitz.open(img_path) as pdf: diff --git a/ppstructure/pdf2word/pdf2word.py b/ppstructure/pdf2word/pdf2word.py index 5c8f8f2bd3..d5d715ed66 100644 --- a/ppstructure/pdf2word/pdf2word.py +++ b/ppstructure/pdf2word/pdf2word.py @@ -22,6 +22,8 @@ import platform import numpy as np import fitz +from paddle.utils import try_import +try_import('fitz') from PIL import Image from pdf2docx.converter import Converter from qtpy.QtWidgets import QApplication, QWidget, QPushButton, QProgressBar, \ diff --git a/requirements.txt b/requirements.txt index af5abe4539..7dc53ca039 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,5 @@ lxml premailer openpyxl attrdict -PyMuPDF<1.21.0 Pillow>=10.0.0 pyyaml