解决“tesseract&tesserocr安装”问题

问题描述

学习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'

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Tesseract是一款开源的OCR引擎,可用于将图像中的文本转换为可编辑的文本格式。以下是关于Tesseract的安装、使用和配置的一些建议: 1. 安装Tesseract Tesseract可在Windows、Mac OS X和Linux操作系统上运行。您可以从Tesseract的官方网站上下载相应的安装包或源代码。如果您使用的是Linux操作系统,可以使用以下命令安装Tesseract: Ubuntu/Debian: ``` sudo apt-get update sudo apt-get install tesseract-ocr ``` CentOS/Fedora: ``` sudo yum install tesseract ``` 2. 使用Tesseract 安装完成后,您可以使用Tesseract进行OCR识别。以下是使用Tesseract进行简单OCR识别的示例代码: ```python import pytesseract from PIL import Image img = Image.open('test.png') text = pytesseract.image_to_string(img, lang='eng') print(text) ``` 3. 配置Tesseract语言包 Tesseract支持多种语言,您可以通过安装相应的语言包来扩展Tesseract的识别能力。您可以从Tesseract的官方网站上下载语言包或使用下面的命令安装语言包: Ubuntu/Debian: ``` sudo apt-get install tesseract-ocr-[lang] ``` 例如,要安装法语语言包,可以运行以下命令: ``` sudo apt-get install tesseract-ocr-fra ``` CentOS/Fedora: ``` sudo yum install tesseract-langpack-[lang] ``` 例如,要安装法语语言包,可以运行以下命令: ``` sudo yum install tesseract-langpack-fra ``` 安装完成后,您可以使用以下代码来指定语言进行OCR识别: ```python import pytesseract from PIL import Image img = Image.open('test.png') text = pytesseract.image_to_string(img, lang='fra') print(text) ``` 以上是Tesseract的安装、使用和配置的一些建议,希望能帮助到您!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值