TesseractNotFoundError: two docker container python app (docker-compose)

大城市里の小女人 提交于 2020-08-07 08:19:47

问题


I have my python project with tesseract running locally, and it works in Pycharm. I used docker-compose.yml, having two containers (app and t4re) as follows:

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:

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. 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.

Use Tesseract 4 - Docker Container from uwsgi-nginx-flask-docker

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


回答1:


You need to install tesseract in your docker image before using it. By default python:3.6.1 image does not have tesseract in it. You need to take ubuntu base image install tesseract and python in it then continue your work. Here is the docker file for the solution:

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.




回答2:


I had this issue on one of my projects that runs on Docker (a Ubuntu container).
To solve that, I had to:
- install pytesseract via requirements.txt; so it your requirements.txt should contain:

pytesseract  

- you have to install tesseract-ocr. To do that, you have to include the following lines in your 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


来源:https://stackoverflow.com/questions/59820821/tesseractnotfounderror-two-docker-container-python-app-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!