<1>先安装两个依赖库:
brew install tesseract
brew install leptonica
网上有些教程说要安装imagemagick,这里我觉得应该是不需要的,当然也可以用brew命令装上
<2>下载tesserocr 离线包
<3>将/usr/local/Cellar/路径下 leptonica/tesserocr头文件夹复制各一份到tesserocr setup.py路径下
<4>将/usr/local/Cellar/路径下的 leptonica/tesserocr所有的库文件(.dylib)复制到anaconda3/lib/路径下
<5>打开命令行安装tesserocr
sudo CFLAGS="-mmacosx-version-min=10.14" python setup.py install
<6>打开命令行出现错误,直接改正
<7>show the demo
#coding=utf-8 #command line:export LC_ALL=C import locale locale.setlocale(locale.LC_ALL,'C') import tesserocr from PIL import Image image = Image.open('image.png') print(tesserocr.image_to_text(image))