pytesseract:无法访问带有 "Image.open" "Errno 2" 错误的图像

pytesseract: Can't access Image with "Image.open" "Errno 2" error

我是第一次尝试使用 pytesseract。我对 python 也不太满意。我在桌面上创建了一个名为 python_test 的新文件夹。我在 Mac。在这个文件夹中,我有一个 test.png 文件和一个 py 脚本:

from pytesseract import image_to_string
from PIL import Image

print image_to_string(Image.open('test.png'))
print image_to_string(Image.open('test-english.jpg'), lang='eng')

所以从我的终端,我进入 python_test 文件夹然后我是 运行 python read.py 然后我有以下错误:

Traceback (most recent call last):
  File "read.py", line 4, in <module>
    print image_to_string(Image.open('test.png'))
  File "/anaconda/anaconda/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 161, in image_to_string
    config=config)
  File "/anaconda/anaconda/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 94, in run_tesseract
    stderr=subprocess.PIPE)
  File "/anaconda/anaconda/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/anaconda/anaconda/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

我做错了什么?

我遇到了和你一样的错误,安装 tesseract 软件包修复了它(或 tesseract-ocr on debian/ubuntu)。它包含 pytesseract.

在幕后使用的本机代码库

如果未安装底层本机库,图像加载错误似乎是库失败的一种奇怪方式,但你去吧。

安装使用命令(适当插入 sudo)

macOS

brew install tesseract

ubuntu

apt install tesseract-ocr

我也是第一次用的时候报错image_to_string.

您必须更改 pytesseract.py 文件中的以下行。

tesseract_cmd = 'C:\Tesseract-OCR\tesseract'

注意:我正在使用 windows。