解决“tesseract&tesserocr安装”问题

在Mac上安装tesseract和tesserocr库时遇到错误,通过Google搜索和Github上的解决方案,最终使用特定的CC、XCC和CPPFLAGS环境变量成功安装tesserocr。然而,即使安装成功,在Python环境中导入tesserocr时仍然会报错。通过设置locale为'C',可以避免运行时错误并正常运行代码。

问题描述

学习Python爬虫首先要配置环境安装tesseract和tesserocr两个库,但是在Mac上按照书中的指导会出现无法解决的安装错误,经过一天时间的试错,总算把这两个库安装完毕可以使用。

 

解决方法

tesseract&tesserocr安装指南

1.安装tesseract

终端输入指令brew install tesseract

在安装全语言支持版本的时候,指令为brew install tesseract-lang

验证所支持的语言,指令为tesseract --list-langs

 

2.安装tesserocr

终端输入指令

采用指令:

pip3 install tesserocr pilow

 

安装过程及报错:

Collecting tesserocr

  Using cached https://files.pythonhosted.org/packages/92/2d/05a7f8387e93c192919b508e4f4936f232bd3d2ca388b9130ae538a9f9ad/tesserocr-2.4.0.tar.gz

Requirement already satisfied: pillow in /anaconda3/lib/python3.7/site-packages (5.3.0)

Building wheels for collected packages: tesserocr

  Building wheel for tesserocr (setup.py) ... error

  Complete output from command /anaconda3/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/tg/g57hkq3s3g163k6zstsmjfj00000gn/T/pip-install-m92cxqko/tesserocr/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /private/var/folders/tg/g57hkq3s3g163k6zstsmjfj00000gn/T/pip-wheel-zpv8cubn --python-tag cp37:

  Supporting tesseract v4.0.0

  Building with configs: {'libraries': ['tesseract', 'lept'], 'cython_compile_time_env': {'TESSERACT_VERSION': 67108864}}

  running bdist_wheel

  running build

  running build_ext

  building 'tesserocr' extension

  creating build

  creating build/temp.macosx-10.7-x86_64-3.7

  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/anaconda3/include -arch x86_64 -I/anaconda3/include -arch x86_64 -I/anaconda3/include/python3.7m -c tesserocr.cpp -o build/temp.macosx-10.7-x86_64-3.7/tesserocr.o -std=c++11 -DUSE_STD_NAMESPACE

  In file included from tesserocr.cpp:656:

  In file included from /usr/local/include/tesseract/genericvector.h:28:

  In file included from /usr/local/include/tesseract/tesscallback.h:22:

  /usr/local/include/tesseract/host.h:30:10: fatal error: 'cinttypes' file not found

  #include <cinttypes>  // PRId32, ...

           ^~~~~~~~~~~

  1 error generated.

  error: command 'gcc' failed with exit status 1

  

  ----------------------------------------

  Failed building wheel for tesserocr

  Running setup.py clean for tesserocr

Failed to build tesserocr

Installing collected packages: tesserocr

  Running setup.py install for tesserocr ... error

    Complete output from command /anaconda3/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/tg/g57hkq3s3g163k6zstsmjfj00000gn/T/pip-install-m92cxqko/tesserocr/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/tg/g57hkq3s3g163k6zstsmjfj00000gn/T/pip-record-7m0n40sm/install-record.txt --single-version-externally-managed --compile:

    Supporting tesseract v4.0.0

  &nbs

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值