【问题标题】:(Python) Tesseract Installation Problem in Windows(Python) Windows 中的 Tesseract 安装问题
【发布时间】:2020-12-20 21:29:31
【问题描述】:

我已经阅读了其他几个答案,但我仍然被困住了。我想我在做一些愚蠢的事情,但这不起作用:

import pytesseract
from PIL import Image

def tryTesseract(u):
    return(pytesseract.image_to_string(Image.open(u)))


loc = 'C:\\Python\\Lineups\\558.png'

print(pytesseract)
print(tryTesseract(loc))

第一行打印:

init.py'的模块'pytesseract'>

但第二个打印了几行错误并最终导致:

pytesseract.pytesseract.TesseractNotFoundError: tesseract 未安装或不在您的 PATH 中。有关详细信息,请参阅 README 文件。

如果第一行有效,这似乎很奇怪。我相信我已将其正确添加到路径中,并且已正确安装,如下图所示:

完整的错误信息:

针对令人兴奋的新错误进行了编辑。我听从了 user3250052 的建议,现在出现了一个新错误(此处 Python 窗口顶部的 CMD 窗口:)

from PIL import Image

def tryTesseract(u):
    return(pytesseract.image_to_string(Image.open(u)))


loc = os.path.join('C','Python','Lineups','558.png')
pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR'

print(pytesseract)
print(tryTesseract(loc))```

【问题讨论】:

    标签: python python-3.x tesseract python-tesseract


    【解决方案1】:

    这是一个文件不喜欢的错误。 试试

    loc = os.path.join('C','Python','Lineups','558.png')
    

    你可能还需要

    pytesseract.tesseract_cmdloc = r'<full_path_to_your_tesseract_executable>'
    

    【讨论】:

    • 感谢您的回复。我尝试添加它,但得到相同的错误。如果这是问题所在,'print(pytesseract)' 行会起作用吗?
    • 你的权利它不会。顺便说一句,它看起来像一个文件未找到错误。使用 os.path()
    • 啊哈,错误现在不同了,它只是说: FileNotFoundError: [Errno 2] No such file or directory: 'C\\Python\\Lineups\\558.png' 这很奇怪我可以在目录中看到它。其余的错误都消失了……
    • 文件是否有可能在其他程序中打开?
    • 感谢 Dunski,它确实在另一个程序中打开了 - 或者至少,重新启动解决了这个问题。我想我忘记了计算机故障排除的第一条规则......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    • 2014-07-19
    • 1970-01-01
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多