无法在Mac上安装Tesseract-OCR

时间:2018-02-19 23:16:43

标签: python-2.7 tesseract

我试图用pytesseract在python 2.7.14中制作一个OCR程序。当我运行我的代码时:

from PIL import Image
import pytesseract

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

我收到了错误:

IOError: [Errno 2] No such file or directory: 'test.png'

我在很多地方搜索过,似乎我需要安装tesseract-ocr。我跑了:

pip install tesseract-ocr

但是我得到了错误:

收集tesseract-ocr   使用缓存的tesseract-ocr-0.0.1.tar.gz 要求已经满足:cython in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages(来自tesseract-ocr) 安装收集的软件包:tesseract-ocr   运行setup.py install for tesseract-ocr ... error     从命令/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c&#34完成输出;导入setuptools,tokenize; file = ' /private/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/setup.py' ;; f = getattr(tokenize,' open&#39 ;, open )(文件); code = f.read()。replace(' \ r \ n',' \ n'); f.close() ; exec(编译(代码,文件,' exec'))" install --record /var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-U3OoHi-record/install-record.txt --single-version-external-managed --compile:     运行安装     运行构建     运行build_py     找不到文件tesseract_ocr.py(对于模块tesseract_ocr)     找不到文件tesseract_ocr.py(对于模块tesseract_ocr)     运行build_ext     建筑' tesseract_ocr'延期     创建构建     创建build / temp.macosx-10.6-intel-2.7     / usr / bin / clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I / Library / Frameworks / Python.framework /Versions/2.7/include/python2.7 -c tesseract_ocr.cpp -o build / temp.macosx-10.6-intel-2.7 / tesseract_ocr.o     tesseract_ocr.cpp:558:10:致命错误:' leptonica / allheaders.h'文件未找到     #include" leptonica / allheaders.h"              ^     生成1个错误。     错误:命令' / usr / bin / clang'退出状态1失败

Command&#34; /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c&#34; import setuptools,tokenize; file < /strong>='/private/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/setup.py';f=getattr(tokenize,' open&# 39;,open)(文件); code = f.read()。replace(&#39; \ r \ n&#39;,&#39; \ n&#39;); f .close(); exec(编译(代码,文件,&#39; exec&#39;))&#34; install --record /var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-U3OoHi-record/install-record.txt --single-version-external-managed --compile&#34;在/ private / var / folders / rd / lf95py7d7s3dkzft38jh3m8h0000gn / T / pip-build-DTR_fL / tesseract-ocr /

中出现错误代码1失败

无论如何我能解决这个问题吗? (当我尝试其他安装方法时,就会发生同样的错误,比如sudo)

1 个答案:

答案 0 :(得分:1)

您需要安装tesseract本身。

正如文档中所述 https://github.com/tesseract-ocr/tesseract/wiki#homebrew

    brew install tesseract 

我也建议通过brew安装python。 这样你就不会污染系统python安装。

最好也使用virtualenv。