简体   繁体   English

TesseractNotFoundError:两个docker容器python应用程序(docker-compose)

[英]TesseractNotFoundError: two docker container python app (docker-compose)

I have my python project with tesseract running locally, and it works in Pycharm.我有一个在本地运行 tesseract 的 python 项目,它在 Pycharm 中工作。 I used docker-compose.yml, having two containers (app and t4re) as follows:我使用了 docker-compose.yml,有两个容器(app 和 t4re),如下所示:

version: '3'
services:
  app:
    build: .
    image: ocr_app:latest
    depends_on:
      - tesseract
  tesseract:
    image: tesseractshadow/tesseract4re
    container_name: t4re

and my Dockerfile is as follows:我的 Dockerfile 如下:

FROM python:3.6.1
# Create app directory
WORKDIR /app

# Bundle app source
COPY venv/src ./src
COPY venv/data ./data

# Install app dependencies
RUN pip install -r src/requirements.txt

CMD python src/ocr.py

and I keep getting these errors:我不断收到这些错误:

FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'

pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path

I am new to docker and read tons of documents, but I still cannot manage to fix this error.我是 docker 新手并阅读了大量文档,但我仍然无法修复此错误。 I've read the following answers.我已阅读以下答案。 I guess I have to link tesseract to the python app with an environment variable, but I do not know how.我想我必须使用环境变量将 tesseract 链接到 python 应用程序,但我不知道如何。

Use Tesseract 4 - Docker Container from uwsgi-nginx-flask-docker 使用 Tesseract 4 - 来自 uwsgi-nginx-flask-docker 的 Docker 容器

TesseractNotFoundError: tesseract is not installed or it's not in your path TesseractNotFoundError: tesseract 未安装或不在您的路径中

You need to install tesseract in your docker image before using it.在使用之前,您需要在 docker 镜像中安装 tesseract。 By default python:3.6.1 image does not have tesseract in it.默认情况下,python:3.6.1 图像中没有 tesseract。 You need to take ubuntu base image install tesseract and python in it then continue your work.您需要在其中安装 ubuntu 基础映像并安装 tesseract 和 python,然后继续您的工作。 Here is the docker file for the solution:这是解决方案的 docker 文件:

FROM ubuntu:18.04
RUN apt-get --fix-missing update && apt-get --fix-broken install && apt-get install -y poppler-utils && apt-get install -y tesseract-ocr && \
    apt-get install -y libtesseract-dev && apt-get install -y libleptonica-dev && ldconfig && apt-get install -y python3.6 && \
    apt-get install -y python3-pip && apt install -y libsm6 libxext6

Please adjust the python version as per your requirement.请根据您的要求调整python版本。

I had this issue on one of my projects that runs on Docker (a Ubuntu container).我在 Docker(一个 Ubuntu 容器)上运行的一个项目中遇到了这个问题。
To solve that, I had to:为了解决这个问题,我不得不:
- install pytesseract via requirements.txt; - 通过requirements.txt安装pytesseract; so it your requirements.txt should contain:所以你的requirements.txt应该包含:

pytesseract  

- you have to install tesseract-ocr. - 你必须安装tesseract-ocr。 To do that, you have to include the following lines in your dockerfile:为此,您必须在 dockerfile 中包含以下几行:

FROM ubuntu:18.04

ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository -y ppa:alex-p/tesseract-ocr
RUN apt-get update && apt-get install -y tesseract-ocr-all 
RUN apt-get install -y python3-pip python3-minimal libsm6 libxext6 
# To make sure that tesseract-ocr is installed, uncomment the following line.  
# RUN tesseract --version

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM