Re: [問題] pytesseract Error

看板Python作者 (貓橘毛發呆雕像)時間8年前 (2017/03/05 20:37), 編輯推噓1(107)
留言8則, 3人參與, 最新討論串2/2 (看更多)
他把其他 error message 吃掉了,完整的 message: ''' 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 C:\Program Files (x86)\Tesseract-OCR\ 或是直接在 cmd 下執行 SETX /M TESSDATA_PREFIX "C:\Program Files (x86)\Tesseract-OCR\\" ※ 引述《doun (嚕啦嚕啦勒)》之銘言: : 我依照範例打了: : from PIL import Image : import pytesseract : print(pytesseract.image_to_string(Image.open(r'C:\Users\w1.png'))) : 結果顯示: : Traceback (most recent call last): : File "<pyshell#3>", line 1, in <module> : print(pytesseract.image_to_string(Image.open(r'C:\Users\\w1.png'))) : File "E:\system\lib\site-packages\pytesseract\pytesseract.py", line 164, in : image_to_string : raise TesseractError(status, errors) : pytesseract.pytesseract.TesseractError: (1, 'Error opening data file : \\Program Files (x86)\\Tesseract-OCR\\tessdata/eng.traineddata') : 整個晚上找相關的國外資料,都無法解決 : 不曉得有沒有人也遇過這個問題?該如何解? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.100.76.218 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1488717460.A.FAF.html

03/05 21:10, , 1F
非常感謝 解決了! 請問要怎麼看完整的訊息?
03/05 21:10, 1F

03/06 02:35, , 2F
在你最後一行前面插入下面這段:
03/06 02:35, 2F

03/06 02:36, , 3F
pytesseract.pytesseract.get_errors = lambda x:x
03/06 02:36, 3F

03/06 02:36, , 4F
根本原因就是作者的 get_errors 畫蛇添足
03/06 02:36, 4F

03/06 02:37, , 5F
他只印 errmsg 中存在 ERROR 的行,所以訊息也變得很怪
03/06 02:37, 5F

03/06 21:04, , 6F
直接跑 tesseract 就看得到了(?)
03/06 21:04, 6F

03/06 21:05, , 7F
pytesseract 只是用 subprocess wrap tesseract 來執行而已
03/06 21:05, 7F

03/06 23:05, , 8F
這個 wrap 還會把錯誤訊息吃掉XD
03/06 23:05, 8F
文章代碼(AID): #1Ol0QK-l (Python)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1Ol0QK-l (Python)