无法让 tesseract 在 python 上工作

Trouble getting tesseract to work on python

当我尝试 运行 在 jupyter notebook 或 pycharm 上使用 tesseract 的代码时遇到了一些麻烦。我怀疑 Windows 7 上的安装有问题,但我不确定我做错了什么。

所以我尝试了很多不同的东西,从 pip install tesseract 和 pytesseract 到安装 tesseract OCR(起初我以为这只是一个库,这就是我搞乱顺序的原因)如下: https://github.com/tesseract-ocr/tesseract/wiki 我实际上已经下载了这个 Cygwin 和 MSYS2,尽管我看到了一些他们没有安装的 youtube 视频。 我什至在我的系统上找到了正确的地址。

好的,所以我使用一个简单的代码来举例说明:

from PIL import Image                                                           
import pytesseract

img = Image.open("teste.png")
print(img)
text = pytesseract.image_to_string(img)                              
print ('Image text:', text)

错误消息相当大,但我认为它会在这一行自行恢复:

TesseractNotFoundError: C:\Program Files\Tesseract-OCR is not installed or it's not in your path

问题是我确实把它放在了: 环境变量——路径——编辑——%SystemRoot%\system32;%SystemRoot%; %SystemRoot%\System32\Wbem; %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\; C:\程序Files\Tesseract-OCR

而且我知道它已安装,因为我可以从 cmd 运行 它...

我总是在 Windows 中遇到 pytesseract 的问题,除非我告诉它可执行文件在哪里:

pytesseract.pytesseract.tesseract_cmd = 'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'