【问题标题】:Error using Pytesser :**[WinError 2] The system cannot find the file specified**使用 Pytesser 时出错:**[WinError 2] 系统找不到指定的文件**
【发布时间】:2019-09-12 04:38:50
【问题描述】:

我得到这个错误:[WinError 2] 系统找不到指定的文件,只有当我使用 pytesser 进行 OCR 时。这是我的代码 sn-p。

from PIL import Image
from pytesseract import *
image = Image.open('pranav.jpg')
print (image_to_string(image))****

否则,当我使用 PIL 更改图像大小时,我不会收到此错误。

【问题讨论】:

  • 你能更新完整的回溯吗?

标签: python pytesser


【解决方案1】:

您不必编辑任何 pytesseract 文件。您可以在代码中声明 Tesseract 安装的路径,如下所示:

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

【讨论】:

  • PermissionError: [WinError 5] 访问被拒绝
【解决方案2】:

我遇到了同样的错误。你必须从这里安装 tesseract: https://code.google.com/p/tesseract-ocr/downloads/detail?name=tesseract-ocr-setup-3.02.02.exe&

然后你必须编辑 pytesseract.py 文件。 就我而言,此文件位于文件夹中:

C:\Users\USERNAME\AppData\Roaming\Python34\site-packages\pytesseract\pytesseract.py

搜索以下行(对我来说是第 60 行):

# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
tesseract_cmd = 'tesseract'

并将其更改为您的 pytesseract.exe 所在的位置,在我的情况下,该行如下所示:

# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
tesseract_cmd = 'c:\\Program Files (x86)\\Tesseract-OCR\\tesseract'

现在您的代码应该可以工作了。

【讨论】:

    【解决方案3】:

    在环境变量中添加 tesseract 路径。

    至少我是这样解决的。

    【讨论】:

      【解决方案4】:
      1. 您可以从这里下载 tesseract: https://github.com/UB-Mannheim/tesseract/wiki

        最新的安装程序可以在这里下载:tesseract-ocr-setup-3.05.01.exe 和 tesseract-ocr-setup-4.0.0-alpha.20180109.exe(实验性)。有 还提供旧版本。

      2. 编辑你的 pytesseract.py 例如。 C:\Users\USER\Anaconda3\Lib\site-packages\pytesseract.py

        如果 TESSERACT 不在您的路径中或名称不同,请更改此设置 tesseract_cmd = 'c:\Program Files (x86)\Tesseract-OCR\tesseract'

      3. 在 import pytesseract 之后在代码中添加以下语句

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

      【讨论】:

        【解决方案5】:

        设置tesseract_cmd、pytesseract.pytesseract.tesseract_cmd、TESSDATA_PREFIX和tessdata_dir_config如下:

        from PIL import Image
        import pytesseract
        tesseract_cmd = 'D:\\Softwares\\Tesseract-OCR\\tesseract'
        pytesseract.pytesseract.tesseract_cmd = 'D:\\Softwares\\Tesseract-OCR\\tesseract'
        TESSDATA_PREFIX= 'D:\Softwares\Tesseract-OCR'
        tessdata_dir_config = '--tessdata-dir "D:\\Softwares\\Tesseract-OCR\\tessdata"'
        print(pytesseract.image_to_string( Image.open('D:\\ImageProcessing\\f2.jpg'), lang='eng', config=tessdata_dir_config))
        

        【讨论】:

          【解决方案6】:

          要彻底消除错误,请执行以下任务:

          1. 下载 tesseract(32 位|64 位)
          2. 在您的系统中安装相同的文件并记下路径。
          3. 创建环境变量 {tesseract = "path of installation/tesseract.exe"}
          4. 重启内核
          5. 使用以下代码:
          import pytesseract
          
          pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/ tesseract.exe'
          
          from PIL import Image
          value=Image.open("C://Profile_tess.png")
          
          text = pytesseract.image_to_string(value)    
          print("text present in images:",text)
          

          【讨论】:

            猜你喜欢
            • 2023-04-02
            • 2021-05-29
            • 2021-07-14
            • 1970-01-01
            • 2020-06-02
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多