【Mac】安装 tesserocr 遇到的一些坑(‘cinttypes' file not found)

问题描述

tesserocr 是 Python 的一个光学字符识别库,它其实是对 tesseract 做的一层 Python API 封装,所以在安装这个库之前我已经用 Homebrew 成功安装好了 ImageMagick 和 tesseract 库。但接着在用 pip 安装 tesserocr 时,却出现了以下一整页的错误。

看这错误报告,主要问题是'cinttypes' file not found

解决方法

解决 ‘cinttypes' file not found

在 github 找到一个解决办法,用以下命令安装 tesserocr 即可。

CC=clang XCC=clang++ CPPFLAGS="-stdlib=libc++ -DUSE_STD_NAMESPACE -mmacosx-version-min=10.8" pip install tesserocr

下面是他对这段代码的解释。

果然,在终端输入这段代码即可正确安装。

但是又出现了一个新问题,安装成功却在 python 无法 导入 tesserocr。

解决无法导入 tesserocr

解决办法很简单,只要在导入 tesserocr 之前,输入以下两行代码即可。

import locale

locale.setlocale(locale.LC_ALL, 'C')

效果展示

安装好 tesserocr 后,写一个小案例来测试识别验证码。选取的图片如下:

运行效果:

可以看到,虽然 pycharm 中还是会提示错误 “No module named tesserocr”,但这并不影响我们正确运行代码。

posted @ 2019-03-15 13:58  DivebombChen  阅读(1403)  评论(0编辑  收藏  举报