无法在 Mac 上安装 Tesseract-OCR [英] Can't install Tesseract-OCR on Mac

查看:66
本文介绍了无法在 Mac 上安装 Tesseract-OCR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 pytesseract 在 python 2.7.14 中制作 OCR 程序.当我运行我的代码时:

I'm trying to make an OCR program in python 2.7.14 with pytesseract. When I ran my code:

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.我跑了:

I searched in many places, and it seems that I need to install tesseract-ocr. I ran:

pip install tesseract-ocr

但是我得到了错误:

收集tesseract-ocr使用缓存的 tesseract-ocr-0.0.1.tar.gz要求已经满足:/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages中的cython(来自tesseract-ocr)安装收集的包:tesseract-ocr为 tesseract-ocr 运行 setup.py install ... 错误命令/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;file='/private 的完整输出/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install--record/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-U3OoHi-record/install-record.txt --single-version-externally-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.otesseract_ocr.cpp:558:10: 致命错误:找不到leptonica/allheaders.h"文件#include "leptonica/allheaders.h"^产生了 1 个错误.错误:命令/usr/bin/clang"失败,退出状态为 1

Collecting tesseract-ocr Using cached tesseract-ocr-0.0.1.tar.gz Requirement already satisfied: cython in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from tesseract-ocr) Installing collected packages: tesseract-ocr Running setup.py install for tesseract-ocr ... error Complete output from command /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;file='/private/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-U3OoHi-record/install-record.txt --single-version-externally-managed --compile: running install running build running build_py file tesseract_ocr.py (for module tesseract_ocr) not found file tesseract_ocr.py (for module tesseract_ocr) not found running build_ext building 'tesseract_ocr' extension creating build creating 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: fatal error: 'leptonica/allheaders.h' file not found #include "leptonica/allheaders.h" ^ 1 error generated. error: command '/usr/bin/clang' failed with exit status 1

Command "/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;file='/private/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))"安装 --record/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-U3OoHi-record/install-record.txt --single-version-externally-managed --compile" 失败,错误代码 1 在/private/var/文件夹/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/

Command "/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;file='/private/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-U3OoHi-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/

无论如何我可以解决这个问题吗?(当我尝试其他安装方式时出现同样的错误,比如 sudo)

Is there anyway I can fix this? (This same error occurred when I tried other ways of installing it, like sudo)

推荐答案

您需要安装 tesseract 本身.

You need to install the tesseract itself.

正如它在文档中所说的那样https://github.com/tesseract-ocr/tesseract/wiki#homebrew

As it says in documentation https://github.com/tesseract-ocr/tesseract/wiki#homebrew

    brew install tesseract 

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

Also I'd recommend installing python through brew as well. That way you won't pollute system python installation.

而且最好也使用 virtualenv.

And it's best to use virtualenv too.

这篇关于无法在 Mac 上安装 Tesseract-OCR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆