【问题记录】06 python使用pytesseract报错:pytesseract.pytesseract.TesseractNotFoundError: tesseract is not inst


1、问题出现

环境:Mac、Python3.9.6。

Python:

import pytesseract
from PIL import Image #用于读取图片

image = Image.open("123.png")
result = pytesseract.image_to_string(image)
print(result1)

使用pytesseract.image_to_string()时报错:

pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.

2、原因分析

本地电脑没有安装tesseract库。

3、解决方法

本地电脑安装tesseract库。

Mac电脑命令行执行:

brew install tesseract

报错:

command not found: brew

先安装brew。

安装命令如下:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

在这里插入图片描述

输入1和y,开始安装brew。

成功之后,继续安装tesseract。

在这里插入图片描述

安装成功之后,添加环境变量:

通过如下命令,打开电脑环境变量文件:

nano ~/.bash_profile

文件最后添加(这个目录,安装brew时可以看到):

export PATH=/opt/homebrew/Cellar/tesseract/5.3.4:$PATH

退出文件之后,通过如下命令,使配置文件生效:

source ~/.bash_profile

生效之后,重启下开发环境,我是使用的VSCode,重新打开Python代码,运行程序即可。

  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: Pytesseract是一个Python的OCR库,可以识别图片中的文本信息。然而,当我们在使用Pytesseract时,会出现“pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed”这个错误,这是因为系统中没有安装TesseractTesseract是一个OCR引擎,用于文字识别。如果我们想要使用Pytesseract,必须先安装TesseractTesseract的安装过程有点繁琐,需要下载并安装Tesseract的二进制文件,并将其添加到环境变量中,然后才能够在Python中调用Pytesseract。 解决这个问题的方法就是安装Tesseract。可以在Tesseract的官网(https://github.com/tesseract-ocr/tesseract)上下载适合自己电脑系统的二进制文件,然后安装。安装成功后,需要将Tesseract添加到环境变量中,以便Pytesseract能够在Python中调用。 总之,一个PytesseractTesseract is not installed错误,通常是因为缺少Tesseract二进制文件或没有将其添加到环境变量中。我们只需要按照官网的步骤安装Tesseract,就可以成功解决这个问题了。 ### 回答2: pytesseract是一种Python的OCR(Optical Character Recognition, 光学字符识别)库,它的作用是通过识别图片中的文本来进行字符识别。在使用pytesseract库时,常常会遇到“pytesseract.pytesseract.TesseractNotFoundError: Tesseract is not installed o”的报错。 这个错误提示的意思是pytesseract无法找到安装在本地计算机中的tesseract程序。由于tesseract是pytesseract库的基础,因此这个错误意味着pytesseract库无法正常工作。 要解决这个问题比较简单,只需要在本地计算机中安装tesseract即可。安装tesseract的方法有很多,具体步骤如下: 第一步:前往tesseract官网下载相应的安装程序 tesseract官网的地址是:https://github.com/UB-Mannheim/tesseract/wiki。在该官网上找到安装程序并下载。 第二步:安装tesseract 安装程序下载后,按照提示一步一步完成安装即可。 第三步:将tesseract的安装路径添加至系统变量中 完成tesseract的安装后,需要将安装路径添加到系统环境变量中。如此一来,pytesseract库便可正常识别图片中的字符和数字,避免了“pytesseract.pytesseract.TesseractNotFoundError: Tesseract is not installed o”的问题。 总之,通过安装tesseract程序并将其路径添加到系统环境变量中,就可以摆脱“pytesseract.pytesseract.TesseractNotFoundError: Tesseract is not installed o”的报错,并正常使用pytesseract库进行图片识别。 ### 回答3: pytesseract是一个用于识别图像中文字的Python库,它使用Tesseract OCR引擎进行识别。当我们在运行时出现"pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed"的错误时,这是因为我们没有安装或没有正确配置Tesseract OCR引擎在我们的系统上。 Tesseract OCR是一个开源的OCR引擎,它能够将图像中的文字识别出来。但是,pytesseract作为一个Python库,需要Tesseract OCR的二进制可执行文件来运行。因此,在使用pytesseract之前,我们需要先安装Tesseract OCR。 在Ubuntu和Debian上,可以通过以下命令安装Tesseract OCR: sudo apt-get install tesseract-ocr 在Windows上,可以从官网下载安装程序进行安装,并在系统环境变量中设置Tesseract OCR的路径。 在安装好Tesseract OCR之后,我们需要配置pytesseract使用正确的Tesseract OCR路径。可以通过以下代码设置: pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract' 或者 pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe' 上述代码指定了Tesseract OCR的二进制可执行文件的路径。如果仍然出现"pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed"的错误,我们需要检查路径是否正确。 总之,当我们在使用pytesseract时出现"pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed"的错误时,通常是由于我们没有安装或配置Tesseract OCR引擎造成的。我们需要先安装Tesseract OCR,并正确配置pytesseract使用正确的Tesseract OCR路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

joinclear

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值