python-3.x - 如何在 Windows 的 Anaconda 上的虚拟环境中安装和使用 PyOCR
问题描述
我想使用 Python 对图片进行文本识别。我决定用 Tesseract 尝试 PyOCR。我在 Windows 机器上使用 Anaconda,但代码应该可以轻松部署在任何环境中。所以我创建了一个名为“ocr_server”的虚拟环境。
如果我在我的机器上安装了所有必需的包,那么第一步就可以了,但是如果我只在 virtualenv 中安装它们,它就不会。
到目前为止我已经尝试过:
- 安装(在 Anaconda 的外壳中):
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
- 使用(在 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 - 基于列分布随机抽样 Pandas 数据帧
- go - 理解 Go 中的变量作用域
- ms-access - Access 2016 中缺少另存为选项
- java - 设置spark连接超时的最简单方法
- api - 企业 Zenhub API 在尝试访问存储库时返回“消息”:“标头中缺少身份验证令牌”
- asp.net-core - IdentityServer4-挑战对 API 的所有请求,而不仅仅是 [授权]
- javascript - 如何仅显示用户从组件写入另一个组件的文本?
- kubernetes - kong 入口控制器对入口资源没有影响
- c++ - 对象超出范围/转移所有权
- sql - 通过 SQL Server 角色或 Windows 组实施安全性