Pytesseract No such file or directory 错误

Pytesseract No such file or directory error

首先我做了这里提到的所有事情

还是不行。现在我使用 Pycharm IDE 和以下代码:

from PIL import Image
import pytesseract
import subprocess

im = Image.open('test.png')
im.show()
subprocess.call(['tesseract','test.png','out'])
print pytesseract.image_to_string(Image.open('test.png'))

我不明白。为什么我可以在 shell 中使用 tesseract 但不能在 python 中使用。在 python 中,我可以打开相同的图像,但是当与 tesseract 一起使用时,找不到图像。

下面你可以看到错误输出。

 File "/home/hamza-c/Schreibtisch/Android/JioShare/orc.py", line 7, in <module>
    print pytesseract.image_to_string(Image.open('/home/hamza-c/Schreibtisch/Android/JioShare/test.png'))
  File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 162, in image_to_string
    config=config)
  File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 95, in run_tesseract
    stderr=subprocess.PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1340, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

我解决了我自己的问题。

im = Image.open('test.png')
print pytesseract.image_to_string(im)

目前还不清楚为什么它在传递引用时起作用,但在我尝试在参数中打开图像时却不能直接起作用。

我测试了你在问题中提到的代码。它工作正常。我遇到了同样的错误

No such file or directory found

问题是包含 'tesseract.exe' 的目录没有添加到环境变量中。您应该能够在命令提示符下 运行 命令 'tesseract' 。

如果未安装 tesseract,您可以从 tesseract 下载它 1: https://github.com/tesseract-ocr/tesseract/wiki and for windows use third party installer available here

也许你需要安装tesseract,如果你的os是centos,请输入

yum install tesseract

我使用了以下命令并且对我有用:

brew install tesseract