【问题标题】:Error while installing tesseract-ocr安装 tesseract-ocr 时出错
【发布时间】:2018-11-26 12:51:41
【问题描述】:

我想将 pytesseract 用于 ocr。所以安装了它。但在此之前我需要安装 tesseract-ocr。我正在使用 Windows 8.1。我打开命令行并运行命令 pip install tesseract-ocr。以下几行是该命令的结果。

我无法理解这里发生了什么。我如何理解这一点并帮助我在我的电脑上成功安装 tesseract?

C:\Users\HarshLaptop>pip install tesseract-ocr
Collecting tesseract-ocr
  Using cached https://files.pythonhosted.org/packages/e2/0d/dcee3dd0fc4c7bcd181
25a98f8ba6d9db7aecaa40770595203e312649587/tesseract-ocr-0.0.1.tar.gz
Requirement already satisfied: cython in c:\users\harshlaptop\anaconda3\lib\site
-packages (from tesseract-ocr) (0.25.2)
Building wheels for collected packages: tesseract-ocr
  Running setup.py bdist_wheel for tesseract-ocr ... error
  Complete output from command c:\users\harshlaptop\anaconda3\python.exe -u -c "
import setuptools, tokenize;__file__='C:\\Users\\HARSHL~1\\AppData\\Local\\Temp\
\pip-install-x8nz3uhm\\tesseract-ocr\\setup.py';f=getattr(tokenize, 'open', open
)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __f
ile__, 'exec'))" bdist_wheel -d C:\Users\HARSHL~1\AppData\Local\Temp\pip-wheel-s
j29zfyo --python-tag cp36:
  running bdist_wheel
  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.win-amd64-3.6
  creating build\temp.win-amd64-3.6\Release
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c
 /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\harshlaptop\anaconda3\include -Ic:\
users\harshlaptop\anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual S
tudio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10
240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Pro
gram Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows
Kits\8.1\include\winrt" /EHsc /Tptesseract_ocr.cpp /Fobuild\temp.win-amd64-3.6\R
elease\tesseract_ocr.obj
  tesseract_ocr.cpp
  tesseract_ocr.cpp(463): fatal error C1083: Cannot open include file: 'leptonic
a/allheaders.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN
\\x86_amd64\\cl.exe' failed with exit status 2

  ----------------------------------------
  Failed building wheel for tesseract-ocr
  Running setup.py clean for tesseract-ocr
Failed to build tesseract-ocr
Installing collected packages: tesseract-ocr
  Running setup.py install for tesseract-ocr ... error
    Complete output from command c:\users\harshlaptop\anaconda3\python.exe -u -c
 "import setuptools, tokenize;__file__='C:\\Users\\HARSHL~1\\AppData\\Local\\Tem
p\\pip-install-x8nz3uhm\\tesseract-ocr\\setup.py';f=getattr(tokenize, 'open', op
en)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, _
_file__, 'exec'))" install --record C:\Users\HARSHL~1\AppData\Local\Temp\pip-rec
ord-vnlr99lk\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.win-amd64-3.6
    creating build\temp.win-amd64-3.6\Release
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe
/c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\harshlaptop\anaconda3\include -Ic
:\users\harshlaptop\anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual
 Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.
10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\P
rogram Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Window
s Kits\8.1\include\winrt" /EHsc /Tptesseract_ocr.cpp /Fobuild\temp.win-amd64-3.6
\Release\tesseract_ocr.obj
    tesseract_ocr.cpp
    tesseract_ocr.cpp(463): fatal error C1083: Cannot open include file: 'lepton
ica/allheaders.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\B
IN\\x86_amd64\\cl.exe' failed with exit status 2

    ----------------------------------------
Command "c:\users\harshlaptop\anaconda3\python.exe -u -c "import setuptools, tok
enize;__file__='C:\\Users\\HARSHL~1\\AppData\\Local\\Temp\\pip-install-x8nz3uhm\
\tesseract-ocr\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.rea
d().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" insta
ll --record C:\Users\HARSHL~1\AppData\Local\Temp\pip-record-vnlr99lk\install-rec
ord.txt --single-version-externally-managed --compile" failed with error code 1
in C:\Users\HARSHL~1\AppData\Local\Temp\pip-install-x8nz3uhm\tesseract-ocr\`enter code here`

【问题讨论】:

标签: python windows-8.1 ocr command-prompt tesseract


【解决方案1】:

要安装 leptonica,您需要关注此link

conda install -c conda-forge leptonica

但是,为了消除安装 tesseract-ocr 时出现的错误,这根本不是一个完整的解决方案。

您需要使用可用的 Windows 安装程序 here 安装 tesseract。然后你应该将 python 包装器安装为:

pip install pytesseract

最后但并非最不重要的一点是,在导入 pytesseract 库后,您还应该在脚本中设置 tesseract 路径,如下所示(请不要忘记安装路径可能会根据您的情况进行修改!):

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'

【讨论】:

    【解决方案2】:

    我也有同样的问题。使用 Visual Studio 2017,在 Windows 10 机器上安装 python 3.6。对我有用的是:

    1. https://github.com/UB-Mannheim/tesseract/wiki 下载并安装 tesseract-ocr 可执行文件(脚本假定 从 Windows 系统运行并将 tesseract 安装保存到 建议的默认位置,即C:\程序文件 (x86)\Tesseract-OCR) 见 https://github.com/tesseract-ocr/tesseract/wiki了解更多信息 在不同的操作系统类型(包括 Windows)上安装时,使用 预构建的二进制包。
    2. 确保您已安装 Python Imaging Library('PIL') 或 'pillow' 软件包以打开图像。 (安装 PIL 在我的 设置,但枕头做了,即 pip 安装枕头)。你需要的理由 这是因为 pytesseract 需要它。看 https://pypi.org/project/pytesseract/0.2.5/ 了解更多信息。
    3. 然后要在您的代码中成功使用它,只需在您的代码中设置 tesseract_cmd 路径,如下所示:

      from PIL import Image
      import pytesseract
      
      try:
      img = Image.open(path/to/image.png) 
      pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract'
      text = pytesseract.image_to_string(path/to/image.png)
      Print(text)
      

      希望对您有所帮助。

    【讨论】:

      【解决方案3】:

      你需要安装 leptonica。Tesseract 需要它。

      【讨论】:

      • leptonica 是什么?
      • Leptonica 是 tesseract 的库和依赖项。github.com/DanBloomberg/leptonica
      • 我已经安装了 Visual Studio。还需要 leptonica 吗?
      • 是的,我的朋友,它是一个 tesseract 使用并依赖于它的图像处理库。
      猜你喜欢
      • 2016-05-01
      • 2014-07-10
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2018-02-25
      • 2018-07-30
      • 1970-01-01
      相关资源
      最近更新 更多