[英]TesseractNotFoundError: two docker container python app (docker-compose)
我有一個在本地運行 tesseract 的 python 項目,它在 Pycharm 中工作。 我使用了 docker-compose.yml,有兩個容器(app 和 t4re),如下所示:
version: '3'
services:
app:
build: .
image: ocr_app:latest
depends_on:
- tesseract
tesseract:
image: tesseractshadow/tesseract4re
container_name: t4re
我的 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
我不斷收到這些錯誤:
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path
我是 docker 新手並閱讀了大量文檔,但我仍然無法修復此錯誤。 我已閱讀以下答案。 我想我必須使用環境變量將 tesseract 鏈接到 python 應用程序,但我不知道如何。
在使用之前,您需要在 docker 鏡像中安裝 tesseract。 默認情況下,python:3.6.1 圖像中沒有 tesseract。 您需要在其中安裝 ubuntu 基礎映像並安裝 tesseract 和 python,然后繼續您的工作。 這是解決方案的 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
請根據您的要求調整python版本。
我在 Docker(一個 Ubuntu 容器)上運行的一個項目中遇到了這個問題。
為了解決這個問題,我不得不:
- 通過requirements.txt安裝pytesseract; 所以你的requirements.txt應該包含:
pytesseract
- 你必須安裝tesseract-ocr。 為此,您必須在 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.