Python安装pytesseract0.3.10异常处理

使用 pytesseract + tesseract-ocr 进行验证码识别,需要安装的第三方库:pytesseract 、tesseract-ocr,在使用pytesseract 之前,必须安装tesseract-ocr,因为 pytesseract 依赖于tesseract-ocr,否则无法使用。若只是安装了pytesseract,在使用pytesseract打开图片是遇到错误,没有找到文件。报错如下:

pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH

一、安装pytesseract0.3.10

pip install pytesseract # 下载慢,则开启代理
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pytesseract  #清华
pip install -i http://pypi.douban.com/simple/  pytesseract  # 豆瓣

二、安装tesseract-ocr5.3.1.20230401(需要手动下载并配置)

点击下载:Home · UB-Mannheim/tesseract Wiki · GitHub,如图:

注意:若尝试多次打不开github,可以产生配置hosts(C:\Windows\System32\drivers\etc),如图:

 安装完成后,如图:

配置环境变量:

变量名:path

值:F:\Tesseract-OCR(你的安装路径)

变量名(新建):TESSDATA_PREFIX

值:F:\Tesseract-OCR\tessdata(你的安装路径下的tessdata文件)

 

 打开cmd,键入:tesseract -v,打印版本信息

 三、配置pytesseract.py

找到python安装目录下的,\Lib\site-packages\pytesseract的pytesseract.py修改如下:tesseract_cmd = 'tesseract',修改成tesseract_cmd = r'F:\Tesseract-OCR\tesseract.exe'(你安装的tesseract-OCR下的\tesseract.exe)

 配置完成后,再运行脚本。就能解决异常问题。

pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
pytesseract是一个基于Python的OCR工具,它使用Google的Tesseract-OCR引擎作为底层。它能够识别图片中的文字,并且支持多种图片格式,如jpeg、png、gif、bmp和tiff等。你可以通过在Python安装pytesseract包并引入其模块来使用它。 要使用pytesseract进行图片文字识别,首先需要安装Tesseract-OCR引擎。你可以在Tesseract OCR的GitHub页面上找到它的地址:https://github.com/tesseract-ocr/tesseract。根据该页面上的说明,下载并安装适合你操作系统的版本。 安装完Tesseract-OCR引擎后,可以通过pip命令安装pytesseract包,命令为:pip install pytesseract安装完成后,你可以在Python中引入pytesseract模块,并使用它的image_to_string函数来识别图片中的文字。 下面是一个简单的例子,展示了如何使用pytesseract进行图片文字识别: ``` import pytesseract from PIL import Image # 打开图片 image = Image.open('example.jpg') # 使用pytesseract进行文字识别 text = pytesseract.image_to_string(image) # 输出识别结果 print(text) ``` 在这个例子中,我们首先使用PIL库打开一张图片。然后,通过调用pytesseract的image_to_string函数来识别图片中的文字。最后,将识别结果打印出来。 需要注意的是,pytesseract的识别结果可能受到图片质量、文字清晰度等因素的影响,所以在使用时,你可能需要对图片进行预处理,如裁剪、调整亮度和对比度等操作,以提高识别率。 总结起来,使用pytesseract进行图片文字识别的步骤包括:安装Tesseract-OCR引擎、安装pytesseract包、导入pytesseract模块、打开图片、调用image_to_string函数进行文字识别、处理识别结果。希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值