gpt4 book ai didi

python-2.7 - 无法在 Mac 上安装 Tesseract-OCR

转载 作者:行者123 更新时间:2023-12-05 04:07:11 29 4
gpt4 key购买 nike

我正在尝试使用 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 为 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)(文件);代码=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: 运行安装 运行构建 运行 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: fatal error :找不到“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 "import setuptools, tokenize;file='/private/var/folders/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/setup.py';f=getattr(tokenize, 'open', open)(文件); 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"失败,错误代码为 1 in/private/var/文件夹/rd/lf95py7d7s3dkzft38jh3m8h0000gn/T/pip-build-DTR_fL/tesseract-ocr/

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

最佳答案

您需要安装 tesseract 本身。

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

    brew install tesseract 

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

最好也使用 virtualenv。

关于python-2.7 - 无法在 Mac 上安装 Tesseract-OCR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48875597/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com