首页 > 解决方案 > 如何在 Windows 的 Anaconda 上的虚拟环境中安装和使用 PyOCR

问题描述

我想使用 Python 对图片进行文本识别。我决定用 Tesseract 尝试 PyOCR。我在 Windows 机器上使用 Anaconda,但代码应该可以轻松部署在任何环境中。所以我创建了一个名为“ocr_server”的虚拟环境。

如果我在我的机器上安装了所有必需的包,那么第一步就可以了,但是如果我只在 virtualenv 中安装它们,它就不会。

到目前为止我已经尝试过:

    conda create -n ocr_server anaconda
    conda activate ocr_server
    conda install -c conda-forge tesseract  # I assume the exe file (found here: https://github.com/UB-Mannheim/tesseract/wiki) is not necessary
    conda install -c conda-forge pytesseract

然后我在https://github.com/tesseract-ocr/tesseract/wiki/Data-Files上下载了语言文件,并将它们放在我的 virtualenv 的 tessdata 文件夹中。

    pip install pyocr
    python -m ipykernel install --user --name=ocr_server  # To use it in JupyterLab
    from PIL import Image
    import sys

    import pyocr
    import pyocr.builders
#    import pytesseract

    tools = pyocr.get_available_tools()
    tools

结果:没有检测到任何工具。但是如果我在我的机器上安装了 tesseract、pytesseract 和 pyocr(而不仅仅是在 virtualenv 中),我可以使用 Tesseract。

我可以尝试什么来解决这个问题?

预先感谢。

标签: python-3.xwindows-10anacondaocrvirtual-environment

解决方案


推荐阅读