py报错:pytesseract.pytesseract.Tesseract

看重点、看重点、看重点
看到好多教程都讲到,在D:\Python37\Lib\site-packages\pytesseract路径下修改pytesseract.py文件
如:
将这个tesseract_cmd = 'tesseract' 改为:tesseract_cmd ='D:\Program Files (x86)\Tesseract-OCR\tesseract.exe'

实际上正确修改方法

需要在tesseract_cmd = 'D:\Program Files (x86)\Tesseract-OCR\tesseract.exe’前面加个r,tesseract_cmd =r‘D:\Program Files (x86)\Tesseract-OCR\tesseract.exe’
或不加r换为反斜杠tesseract_cmd = 'D:/Program Files (x86)/Tesseract-OCR/tesseract.exe'(注:新手一定要注意/与\的区分)
再或不加r加双斜杆tesseract_cmd ='D:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
这样执行完后应该不会再报系统找不到指定文件的错了……

import pytesseract
from PIL import Image

image = Image.open("c_th2.jpg")
code = pytesseract.image_to_string(image)
print(code)