无法在Buster Docker上使用pip安装tesserocr。

huangapple go评论66阅读模式
英文:

Can't install tesserocr using pip on buster docker

问题

以下是您的Dockerfile的翻译部分:

FROM python:3.11-buster AS app

WORKDIR /srv/app

ENV PYTHONPATH /srv/app

RUN apt update -y && \
    apt install -y libegl1 libgl1 libxkbcommon-x11-0 dbus tesseract-ocr liblept5 leptonica-progs libleptonica-dev libtesseract-dev
RUN pip install --upgrade pip

您在容器中运行pip install tesserocr时遇到错误。要解决这个问题,建议尝试以下步骤:

  1. 确保您的Docker容器中已安装了tesseract和leptonica等依赖项,这些是tesserocr的依赖项。

  2. 检查您的Python版本是否与tesserocr兼容。某些版本的tesserocr可能不兼容特定的Python版本。您可以尝试更改Python版本或tesserocr版本。

  3. 如果可能,查看tesserocr的文档或GitHub存储库,了解是否有与您的Python版本和依赖项版本匹配的建议安装方式。

  4. 如果问题仍然存在,您可以尝试在Dockerfile中的pip安装之前添加一个步骤,将tesserocr从系统包管理器中安装,以确保所有依赖项都已正确安装。

希望这些步骤能帮助您解决问题。

英文:

Here is my Dockerfile:

FROM python:3.11-buster AS app

WORKDIR /srv/app

ENV PYTHONPATH /srv/app

RUN apt update -y && \
    apt install -y libegl1 libgl1 libxkbcommon-x11-0 dbus tesseract-ocr liblept5 leptonica-progs libleptonica-dev libtesseract-dev
RUN pip install --upgrade pip

When I connect to my container and I launch: pip install tesserocr

I got error:

$ pip install tesserocr
Collecting tesserocr
  Downloading tesserocr-2.6.0.tar.gz (58 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.6/58.6 kB 929.0 kB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: tesserocr
  Building wheel for tesserocr (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [32 lines of output]
      Supporting tesseract v4.0.0
      Tesseract major version 4
      Configs from pkg-config: {'library_dirs': [], 'include_dirs': ['/usr/include', '/usr/include'], 'libraries': ['tesseract', 'lept'], 'compile_time_env': {'TESSERACT_MAJOR_VERSION': 4, 'TESSERACT_VERSION': 67108864}}
      /usr/local/lib/python3.11/site-packages/setuptools/installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
        warnings.warn(
      running bdist_wheel
      running build
      running build_ext
      Detected compiler: unix
      building 'tesserocr' extension
      creating build
      creating build/temp.linux-x86_64-cpython-311
      gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/include -I/usr/include -I/usr/local/include/python3.11 -c tesserocr.cpp -o build/temp.linux-x86_64-cpython-311/tesserocr.o -std=c++11 -DUSE_STD_NAMESPACE
      tesserocr.cpp: In function ‘tesseract::TessResultRenderer* __pyx_f_9tesserocr_13PyTessBaseAPI__get_renderer(__pyx_obj_9tesserocr_PyTessBaseAPI*, __pyx_t_9tesseract_cchar_t*)’:
      tesserocr.cpp:22546:14: error: ‘TessAltoRenderer’ is not a member of ‘tesseract’
         tesseract::TessAltoRenderer *__pyx_t_6;
                    ^~~~~~~~~~~~~~~~
      tesserocr.cpp:22546:14: note: suggested alternative: ‘TessOsdRenderer’
         tesseract::TessAltoRenderer *__pyx_t_6;
                    ^~~~~~~~~~~~~~~~
                    TessOsdRenderer
      tesserocr.cpp:22546:32: error: ‘__pyx_t_6’ was not declared in this scope
         tesseract::TessAltoRenderer *__pyx_t_6;
                                      ^~~~~~~~~
      tesserocr.cpp:22546:32: note: suggested alternative: ‘__pyx_t_5’
         tesseract::TessAltoRenderer *__pyx_t_6;
                                      ^~~~~~~~~
                                      __pyx_t_5
      tesserocr.cpp:22645:23: error: expected type-specifier
             __pyx_t_6 = new tesseract::TessAltoRenderer(__pyx_v_outputbase);
                             ^~~~~~~~~
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for tesserocr
  Running setup.py clean for tesserocr
Failed to build tesserocr
ERROR: Could not build wheels for tesserocr, which is required to install pyproject.toml-based projects

How to solve this ?

答案1

得分: 1

以下是您要翻译的内容:

"I was suffering from the same issue you were, hopefully this is helpful still:

I believe the dependencies for tesserocr are not correctly met with the default packages in the repositories for buster.

Case in point, the apt repository information for Buster suggests tesseract-ocr version 4.0.0-2, and version 5.3.0-2 for the bookworm version. When I run the minimum failing example below in Docker, I receive error output suggesting some kind of incompatibility between tesserocr and tesseract: tesserocr.cpp:22550:14: error: ‘TessAltoRenderer’ is not a member of ‘tesseract’.

However, the working dockerfile requires only an upgrade to bullseye from buster. I believe this has something to do with dependencies, and without a ton of research I'm not sure I'd be able to figure out what specifically has changed, but my suggestion is to upgrade from buster to at least bullseye. I tested it on bookworm as well, and it works (which also lets you use tesseract version 5+).

Here is a Dockerfile which fails to build:

FROM python:3.11.4-buster

WORKDIR /app

RUN apt-get update && apt-get install -y \
  libleptonica-dev \
  tesseract-ocr \
  libtesseract-dev

RUN pip install tesserocr

RUN mkdir src && \
  echo "from tesserocr import PyTessBaseAPI" >> ./src/main.py && \
  echo "with PyTessBaseAPI() as api:" >> ./src/main.py && \
  echo "  print(api.Version())" >> ./src/main.py 

ENTRYPOINT ["python", "./src/main.py"]

Here is a Dockerfile which succeeds to build, and run:

FROM python:3.11.4-bullseye # Also tested with -bookworm

WORKDIR /app

RUN apt-get update && apt-get install -y \
  libleptonica-dev \
  tesseract-ocr \
  libtesseract-dev

RUN pip install tesserocr

RUN mkdir src && \
  echo "from tesserocr import PyTessBaseAPI" >> ./src/main.py && \
  echo "with PyTessBaseAPI() as api:" >> ./src/main.py && \
  echo "  print(api.Version())" >> ./src/main.py 

ENTRYPOINT ["python", "./src/main.py"]
英文:

I was suffering from the same issue you were, hopefully this is helpful still:

I believe the dependencies for tesserocr are not correctly met with the default packages in the repositories for buster.

Case in point, the apt repository information for Buster suggests tesseract-ocr version 4.0.0-2, and version 5.3.0-2 for the bookworm version. When I run the minimum failing example below in Docker, I receive error output suggesting some kind of incompatibility between tesserocr and tesseract: tesserocr.cpp:22550:14: error: ‘TessAltoRenderer’ is not a member of ‘tesseract’.

However, the working dockerfile requires only an upgrade to bullseye from buster. I believe this has something to do with dependencies, and without a ton of research I'm not sure I'd be able to figure out what specifically has changed, but my suggestion is to upgrade from buster to at least bullseye. I tested it on bookworm as well, and it works (which also lets you use tesseract version 5+).

Here is a Dockerfile which fails to build:

FROM python:3.11.4-buster

WORKDIR /app

RUN apt-get update && apt-get install -y \
  libleptonica-dev \
  tesseract-ocr \
  libtesseract-dev

RUN pip install tesserocr

RUN mkdir src && \
  echo "from tesserocr import PyTessBaseAPI" >> ./src/main.py && \
  echo "with PyTessBaseAPI() as api:" >> ./src/main.py && \
  echo "  print(api.Version())" >> ./src/main.py 

ENTRYPOINT ["python", "./src/main.py"]

Here is a Dockerfile which succeeds to build, and run:

FROM python:3.11.4-bullseye # Also tested with -bookworm

WORKDIR /app

RUN apt-get update && apt-get install -y \
  libleptonica-dev \
  tesseract-ocr \
  libtesseract-dev

RUN pip install tesserocr

RUN mkdir src && \
  echo "from tesserocr import PyTessBaseAPI" >> ./src/main.py && \
  echo "with PyTessBaseAPI() as api:" >> ./src/main.py && \
  echo "  print(api.Version())" >> ./src/main.py 

ENTRYPOINT ["python", "./src/main.py"]

huangapple
  • 本文由 发表于 2023年5月18日 10:18:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76277328.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定