运行 pytesseract 出现报错,以下是报错内容:
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it’s not in your PATH. See README file for more information.
报错的本质原因就是程序安装不正确,下面开始一步步教你如何安装。
如果是ubuntu系统,解决方法可查看4行代码识别提取图片中的文字pytesseract
winodos 如下
先安装python包,pytesseract:
pip install pytesseract -i https://pypi.tuna.tsinghua.edu.cn/simple
再安装tesseract.exe文件,下载地址:
https://digi.bib.uni-mannheim.de/tesseract/
版本按照自己需要选择,一般就用最新版本
下载好了双击tesseract.exe软件:
itional language data语言可以全选,如果只是中文识别也可以只选择和Chinese有关的项
最后,代码中需要设置 Tesseract OCR 的执行路径:
pytesseract.pytesseract.tesseract_cmd = r'E:\pc\tesseract-ocr\tesseract.exe
完整的python执行代码
from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'E:\pc\tesseract-ocr\tesseract.exe'
# 加载图像
image = Image.open('../target_img/image_7.png')
# 列出支持的语言
print(pytesseract.get_languages(config=''))
text = pytesseract.image_to_string(image, lang='chi_sim')
print(text)