在安装tesseract-ocr时出现gcc错误:找不到leptonica/allheaders.h文件。

7

我正在尝试在我的Mac上运行以下代码。

import Image
import pytesseract

im = Image.open('test.png')
print(pytesseract.image_to_string(im))

根据这里的问题: pytesseract-no such file or directory error,我需要安装tesseract-ocr。

但是当我尝试使用pip安装tesseract-ocr时,我会遇到以下错误:

creating build/temp.macosx-10.5-x86_64-2.7
gcc -fno-strict-aliasing -I//anaconda/include -arch x86_64 -DNDEBUG -g
-fwrapv -O3 -Wall -Wstrict-prototypes -I//anaconda/include/python2.7 -c
tesseract_ocr.cpp -o build/temp.macosx-10.5-x86_64-2.7/tesseract_ocr.o
tesseract_ocr.cpp:264:10: 
fatal error: 'leptonica/allheaders.h' file not found #include "leptonica/allheaders.h"
     ^
1 error generated.
error: command 'gcc' failed with exit status 1

我不知道该怎么办。


您需要安装一个 C 库,可以在此处 http://www.leptonica.org/download.html 找到;如果您使用的是brew,则可能会有所帮助 brew install leptonica - J.J. Hakala
我尝试了 pip install leptonica,但是收到了另一个错误信息:Could not find a version that satisfies the requirement leptonica (from versions: ) No matching distribution found for leptonica - Jase Villam
1
如果可以执行 pip install leptonica,那么 pip install tesseract-ocr 就会自动安装。 - J.J. Hakala
5个回答

14

您需要在系统中安装 libtesseract-dev

sudo apt install libtesseract-dev

非常感谢!!! 已经生效。 - Red

2

使用yum命令:

yum install leptonica-devel tesseract-devel

1

参考另一篇文章,在我的Mac上找到了最终解决方案:

brew install tesseract

解释:

它将安装后端tesseract和依赖库leptonica(以及其他库:giflib、jpeg、libpng、libtiff、little-cms2、openjpeg、webp),因此可以修复此错误。


在这样做之后,我仍然遇到了错误。在代码中使用tesseract之前,我必须将我的tesseract安装路径设置为一个变量,就像这个答案中所示:https://dev59.com/vlUL5IYBdhLWcg3wCEMA#54995964 - Shad

1
在Linux中使用以下命令。
sudo apt-get install tesseract-ocr

0

尝试这样做,不要在中间使用空格 "pip install easyocr"


1
你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - lpounng

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接