PaddlePaddle / PaddleOCR

Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
https://paddlepaddle.github.io/PaddleOCR/
Apache License 2.0
44.57k stars 7.85k forks source link

ModuleNotFoundError: No module named 'tools.infer' while Detectron2 are installed #13335

Closed yogi0421 closed 4 months ago

yogi0421 commented 4 months ago

问题描述 / Problem Description

When I try to import paddleocr, it return ModuleNotFoundError: No module named 'tools.infer', this happened on my environment with Detectron2 are installed.

运行环境 / Runtime Environment

复现代码 / Reproduction Code

from paddleocr import PaddleOCR

完整报错 / Complete Error Message

Python 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from paddleocr import PaddleOCR
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/dist-packages/paddleocr/__init__.py", line 14, in <module>
    from .paddleocr import *
  File "/usr/local/lib/python3.10/dist-packages/paddleocr/paddleocr.py", line 34, in <module>
    from tools.infer import predict_system
ModuleNotFoundError: No module named 'tools.infer'

可能解决方案 / Possible solutions

I manually edit the paddle.py file, on code from :

from tools.infer import predict_system
from tools.infer.utility import draw_ocr, str2bool, check_gpu

to :

from paddleocr.tools.infer import predict_system
from paddleocr.tools.infer.utility import draw_ocr, str2bool, check_gpu

附件 / Appendix

yogi0421 commented 4 months ago

are this is expected?

GreatV commented 4 months ago

You're right, tools is the generic name, it's better to import it with the namespace paddleocr.

yogi0421 commented 4 months ago

@GreatV did you know the release branch that solved this issue? or this issue are still happen on almost all version of paddleocr?

GreatV commented 4 months ago

@yogi0421 This issue is not yet fixed in the release branch.

myhloli commented 4 months ago

I encountered the same issue, which only occurred in version 2.8.0; there were no problems in version 2.7.3. To resolve it, I replaced tools.infer with paddleocr.tools.infer which fixed the problem.

myhloli commented 4 months ago

@GreatV I carefully reviewed the differences between versions 2.7.3 and 2.8.0, and found that in 2.8.0, "from tools.infer import predict_system" was placed before the definition of the "tools" methods. This is why the issue did not reproduce on 2.7.3. I have already submitted the fix code at https://github.com/PaddlePaddle/PaddleOCR/pull/13348