我正在尝试在python中使用pytesseract,但我总是遇到以下错误:
raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path
但是,我的系统上安装了pytesseract和Tesseract。
产生此错误的示例代码:
import cv2
import pytesseract
img = cv2.imread('1d.png')
print(pytesseract.image_to_string(img))
sudo apt update
# This will update your packages
sudo apt install tesseract-ocr
# This will install OCR
sudo apt install libtesseract-dev
# This will add it as development dependency
注意:仅适用于Windows
我也面临同样的问题,只需将C:\Program Files (x86)\Tesseract-OCR
添加到您的path变量中。如果仍然不起作用,请在新行中将C:\Program Files (x86)\Tesseract-OCR\tessdata
添加到路径变量中。并且不要忘记在添加path变量后重新启动计算机。
which pip3
显示pip3安装的路径,which python3
显示Python安装的对应路径。 当我尝试使用pytesseract制作文本提取程序时,我也遇到了相同的错误,但是在pypi站点中的
pytesseract
的安装说明中有解决方案:pytesseract有很多避免错误的方法,但是,在方法pytesseract.image_to_string
当当前目录位于与tesseract安装位置不同的驱动器上时,在Windows(至少在tesseract版本3.05中)下发生。tesseract中的某些功能期望数据文件位于\ Program Files ...(而不是C:\ Program Files)中。因此,如果您与tesseract不在同一个驱动器号上,它将失败。如果能够解决该问题,那就是在执行tesseract之前临时将驱动器(仅在Windows下)更改为tesseract安装驱动器,然后再进行更改,就可以解决此问题。您的示例:您可以将yourmodule_python.py复制到“ C /程序文件(x86)/ Tesseract-OCR /”并运行!
brew install tesseract
从https://github.com/UB-Mannheim/tesseract/wiki下载二进制文件。然后将pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
添加到脚本中。 (如有必要,请替换tesseract二进制文件的路径)
您可能丢失了计算机的
tesseract-ocr
。在此处查看安装说明:https://github.com/tesseract-ocr/tesseract/wiki在Mac上,您只能使用自制软件进行安装:
设置路径的步骤很少
1:转到此“ https://github.com/UB-Mannheim/tesseract/wiki”
4:在系统变量中设置路径,例如“ C:\ Program Files \ Tesseract-OCR”或“ C:\ ProgramFiles(x86)\ Tesseract-OCR”5:打开CMD类型“ tesseract”和一些输出,但不包含“非矩形类型错误”
对于Mac:
安装Pytesseract(