1

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

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))

第一行打印:

<来自'C:\Python\lib\site-packages\pytesseract\ init .py'的模块'pytesseract'>

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

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

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

cmd截图

完整的错误信息:

Python 错误

编辑了令人兴奋的新错误。我遵循了 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))```
4

1 回答 1

1

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

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

你可能还需要

pytesseract.tesseract_cmdloc = r'<full_path_to_your_tesseract_executable>'
于 2020-12-20T12:24:34.703 回答