[Python] How to solve Tesseract "Failed loading language 'eng'" problem in a Docker image

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    I recently received an error such as:

    File "/usr/local/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 287, in run_and_get_output
    run_tesseract(**kwargs)
    File "/usr/local/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 263, in run_tesseract
    raise TesseractError(proc.returncode, get_errors(error_string))
    pytesseract.pytesseract.TesseractError: (1, "read_params_file: Can't open ][|~_}{=!#%&«§><:;—?¢°*@, Failed loading language 'eng' Tesseract couldn't load any languages! Could not initialize tesseract.")


    I have a python file where I specify the pytesseract location: pytesseract.pytesseract.tesseract_cmd = r"to/my/path"

    then I also included the tesseract and pytessearch in requirements and install tesseract-ocr in dockerfile.

    I do not understand why it happens but can anyone assist?

    I actually also copied my tesseract-ocr folder to image in dockerfile

    COPY tesseract-ocr .


    Edited:

    Below is my requirements:

    opencv-python==4.5.1.48
    openpyxl==3.0.6
    packaging==20.8
    pandas==1.2.1
    pathlib==1.0.1
    patsy==0.5.1
    pdfminer.six==20200517
    pdfplumber==0.5.25
    Pillow==8.1.0
    prov==2.0.0
    pycryptodome==3.9.9
    pydot==1.4.1
    PyMuPDF==1.16.14
    pyparsing==2.4.7
    PyPDF2==1.26.0
    pytesseract==0.3.7
    tesseract


    Below is my dockerfile

    FROM python:3.8.7-slim
    WORKDIR /usr/src/app
    ARG src_folder= "folder/"
    ARG src_ocr= "Tesseract-OCR/"
    COPY ${src_folder} .
    COPY ${src_ocr} .
    COPY requirements.txt .

    # Install all the required dependencies
    RUN apt-get update \
    && apt-get install -y \
    build-essential \
    cmake \
    git \
    wget \
    unzip \
    yasm \
    pkg-config \
    libswscale-dev \
    libtbb2 \
    libtbb-dev \
    libjpeg-dev \
    libpng-dev \
    libtiff-dev \
    libavformat-dev \
    libpq-dev \
    && rm -rf /var/lib/apt/lists/*
    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 install -y libsm6 libxext6 && apt install -y python-opencv
    RUN pip install -r requirements.txt

    # command to run on container start
    CMD [ "python", "./folder/main.py" ]

    Continue reading...

Compartilhe esta Página