【发布时间】:2019-01-27 00:57:02
【问题描述】:
我看到很多其他人遇到了这个错误,我尝试了很多不同的方法来修复它。到目前为止没有任何工作。我有:
- 将路径添加到我的 Tesseract-OCR 文件夹和 tesseract.exe 文件到 PATH
- 添加了一个名为 TESSDATA_PREFIX 的环境变量,它指向 Tesseract-OCR 文件夹
- 多次替换 eng.traneddata 文件
- 在程序中添加了
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe" - 尝试运行 JUST the quickstart file 而不是我正在运行的程序
并没有改变错误。在这一点上,我只是在寻找任何东西。完整的错误如下。
File "pytesseract should work please.py", line 12, in <module>
print(pytesseract.image_to_string(Image.open('text.png')))
File "C:\Users\matth\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 309, in image_to_string
}[output_type]()
File "C:\Users\matth\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 308, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "C:\Users\matth\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 218, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\matth\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 194, in run_tesseract
raise TesseractError(status_code, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (1, 'Error opening data file \\Program Files (x86)\\Tesseract-OCR\\tessdata/eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory. Failed loading language \'eng\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')
【问题讨论】:
-
TESSDATA_PREFIX应该指向带有训练数据文件的文件夹(例如 eng.traineddata) -
真的吗?在错误中显示
Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory.。我确实切换了它,它仍然没有修复它或更改错误。 -
是的,你是对的,它是tessdata,而不是traineddata文件夹。我想指出,它可能不是您提到的“Tesseract-OCR”文件夹。
标签: python tesseract python-tesseract