无法在 Mac 上安装 Tesseract-OCR

2024-04-04

我正在尝试使用 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 已满足要求: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages 中的 cython (来自 tesseract-ocr) 安装收集的包:tesseract-ocr 运行 setup.py install for tesseract-ocr ... 错误 命令 /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(编译(code,file,'exec'))“安装--record /var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-U3OoHi-record/install-record.txt--单一版本-外部管理--编译: 运行安装 运行构建 运行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

命令“/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c”导入setuptools,标记化;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(编译(code,file, 'exec'))" install --record /var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-U3OoHi-record/install-record.txt --single-version-externally-management --compile" 失败并显示错误代码1 在 /private/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/

我能解决这个问题吗? (当我尝试其他方式安装它时,也发生了同样的错误,比如 sudo)


您需要安装 tesseract 本身。

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

    brew install tesseract 

我还建议通过安装 pythonbrew以及。 这样你就不会污染系统 python 安装。

最好也使用 virtualenv。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在 Mac 上安装 Tesseract-OCR 的相关文章

随机推荐