AttributeError:部分初始化的模块“pytesseract”没有属性“image\u to\u string”

2024-06-16 14:35:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我做了pip安装pytesseract,也安装了OCR。 完全错误:

Traceback (most recent call last):
  File "c:/Users/Hackry/Documents/pytest/tess.py", line 2, in <module>
    import pytesseract
  File "c:\Users\Hackry\Documents\pytest\pytesseract.py", line 6, in <module>
    text = pytesseract.image_to_string(img)
AttributeError: partially initialized module 'pytesseract' has no attribute 'image_to_string' (most likely due to a circular import)

我的代码

from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:/Users/Hackry/AppData/Local/Tesseract-OCR/tesseract.exe' #define tesseract path

img = Image.open('C:/Users/Hackry/Documents/pytest/text.jpg')
text = pytesseract.image_to_string(img)

print(text) 

Tags: totextimageimportmostimgstringpytest