【问题标题】:Pytesseract No such file or directory errorPytesseract No such file or directory 错误
【发布时间】:2016-11-01 00:24:23
【问题描述】:

首先我做了这里提到的一切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'))
  • im.show() 成功打开图片。
  • subprocess.call() with tesseract test.png out 也提取文本 从图片..
  • 但是 pytesseract.image_to_string() 失败。

我不明白。为什么我能够在 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

【问题讨论】:

  • 我遇到了同样的问题并找到了解决方案Here

标签: python image text pycharm tesseract


【解决方案1】:

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

找不到这样的文件或目录

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

如果没有安装tesseract,你可以从tesseract下载 1:https://github.com/tesseract-ocr/tesseract/wiki 和 Windows 使用第三方安装程序可用here

【讨论】:

  • 如何添加到环境变量中?你是怎么解决的?
【解决方案2】:

也许你需要安装tesseract,如果你的操作系统是centos,请输入

yum install tesseract

【讨论】:

    【解决方案3】:

    我使用了以下命令,它对我有用:

    brew install tesseract
    

    【讨论】:

      【解决方案4】:

      我解决了我自己的问题。

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

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

      【讨论】:

        猜你喜欢
        • 2020-03-19
        • 1970-01-01
        • 1970-01-01
        • 2023-04-03
        • 1970-01-01
        • 2018-09-30
        • 2019-03-25
        • 2014-11-09
        • 1970-01-01
        相关资源
        最近更新 更多