今天在安裝使用pytesseract的時候遇到的兩個,在這裏記錄一下解決方案。
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path
這個問題是因爲我們在python中要想使用tesseract,不只是需要安裝pytesseract庫,還需要安裝tesseract程序,並將路徑添加到pytesseract中。
這裏貼一個下載地址:https://github.com/tesseract-ocr/tesseract/wiki
然後需要將pytesseract.py中的tesseract_cmd改爲安裝的地址,如下圖所示。如果是pycharm用戶的話直接連按兩下shift進行搜索即可。
windows 10 :pytesseract.pytesseract.TesseractError: (1, 'Error opening data file \\Program Files (x86)\\Tesseract-OCR\\tessdata/chi_sim.traineddata') #50
這個錯誤是因爲tesseract和你的項目沒有放在同一個硬盤,所以會報錯。這種情況只需要重新安裝在對應的硬盤即可。
我實在github上找到的解決方案:https://github.com/madmaze/pytesseract/issues/50
一點題外話
另外就是pytesseract一般是用來對付圖形驗證碼的手段,但是直接識別的話其實效果會很差。針對不同的場景,應該自己訓練一個對應的文字庫。這裏放一個鏈接,裏面有教程:https://www.cnblogs.com/chen0307/p/9837003.html