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

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

Can't install tesserocr using pip on buster docker

问题

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

  1. FROM python:3.11-buster AS app
  2. WORKDIR /srv/app
  3. ENV PYTHONPATH /srv/app
  4. RUN apt update -y && \
  5. apt install -y libegl1 libgl1 libxkbcommon-x11-0 dbus tesseract-ocr liblept5 leptonica-progs libleptonica-dev libtesseract-dev
  6. 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:

  1. FROM python:3.11-buster AS app
  2. WORKDIR /srv/app
  3. ENV PYTHONPATH /srv/app
  4. RUN apt update -y && \
  5. apt install -y libegl1 libgl1 libxkbcommon-x11-0 dbus tesseract-ocr liblept5 leptonica-progs libleptonica-dev libtesseract-dev
  6. RUN pip install --upgrade pip

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

I got error:

  1. $ pip install tesserocr
  2. Collecting tesserocr
  3. Downloading tesserocr-2.6.0.tar.gz (58 kB)
  4. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.6/58.6 kB 929.0 kB/s eta 0:00:00
  5. Preparing metadata (setup.py) ... done
  6. Building wheels for collected packages: tesserocr
  7. Building wheel for tesserocr (setup.py) ... error
  8. error: subprocess-exited-with-error
  9. × python setup.py bdist_wheel did not run successfully.
  10. exit code: 1
  11. ╰─> [32 lines of output]
  12. Supporting tesseract v4.0.0
  13. Tesseract major version 4
  14. 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}}
  15. /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.
  16. warnings.warn(
  17. running bdist_wheel
  18. running build
  19. running build_ext
  20. Detected compiler: unix
  21. building 'tesserocr' extension
  22. creating build
  23. creating build/temp.linux-x86_64-cpython-311
  24. 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
  25. tesserocr.cpp: In function tesseract::TessResultRenderer* __pyx_f_9tesserocr_13PyTessBaseAPI__get_renderer(__pyx_obj_9tesserocr_PyTessBaseAPI*, __pyx_t_9tesseract_cchar_t*)’:
  26. tesserocr.cpp:22546:14: error: TessAltoRenderer is not a member of tesseract
  27. tesseract::TessAltoRenderer *__pyx_t_6;
  28. ^~~~~~~~~~~~~~~~
  29. tesserocr.cpp:22546:14: note: suggested alternative: TessOsdRenderer
  30. tesseract::TessAltoRenderer *__pyx_t_6;
  31. ^~~~~~~~~~~~~~~~
  32. TessOsdRenderer
  33. tesserocr.cpp:22546:32: error: __pyx_t_6 was not declared in this scope
  34. tesseract::TessAltoRenderer *__pyx_t_6;
  35. ^~~~~~~~~
  36. tesserocr.cpp:22546:32: note: suggested alternative: __pyx_t_5
  37. tesseract::TessAltoRenderer *__pyx_t_6;
  38. ^~~~~~~~~
  39. __pyx_t_5
  40. tesserocr.cpp:22645:23: error: expected type-specifier
  41. __pyx_t_6 = new tesseract::TessAltoRenderer(__pyx_v_outputbase);
  42. ^~~~~~~~~
  43. error: command '/usr/bin/gcc' failed with exit code 1
  44. [end of output]
  45. note: This error originates from a subprocess, and is likely not a problem with pip.
  46. ERROR: Failed building wheel for tesserocr
  47. Running setup.py clean for tesserocr
  48. Failed to build tesserocr
  49. 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:

  1. FROM python:3.11.4-buster
  2. WORKDIR /app
  3. RUN apt-get update && apt-get install -y \
  4. libleptonica-dev \
  5. tesseract-ocr \
  6. libtesseract-dev
  7. RUN pip install tesserocr
  8. RUN mkdir src && \
  9. echo "from tesserocr import PyTessBaseAPI" >> ./src/main.py && \
  10. echo "with PyTessBaseAPI() as api:" >> ./src/main.py && \
  11. echo " print(api.Version())" >> ./src/main.py
  12. ENTRYPOINT ["python", "./src/main.py"]

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

  1. FROM python:3.11.4-bullseye # Also tested with -bookworm
  2. WORKDIR /app
  3. RUN apt-get update && apt-get install -y \
  4. libleptonica-dev \
  5. tesseract-ocr \
  6. libtesseract-dev
  7. RUN pip install tesserocr
  8. RUN mkdir src && \
  9. echo "from tesserocr import PyTessBaseAPI" >> ./src/main.py && \
  10. echo "with PyTessBaseAPI() as api:" >> ./src/main.py && \
  11. echo " print(api.Version())" >> ./src/main.py
  12. 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:

  1. FROM python:3.11.4-buster
  2. WORKDIR /app
  3. RUN apt-get update && apt-get install -y \
  4. libleptonica-dev \
  5. tesseract-ocr \
  6. libtesseract-dev
  7. RUN pip install tesserocr
  8. RUN mkdir src && \
  9. echo "from tesserocr import PyTessBaseAPI" >> ./src/main.py && \
  10. echo "with PyTessBaseAPI() as api:" >> ./src/main.py && \
  11. echo " print(api.Version())" >> ./src/main.py
  12. ENTRYPOINT ["python", "./src/main.py"]

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

  1. FROM python:3.11.4-bullseye # Also tested with -bookworm
  2. WORKDIR /app
  3. RUN apt-get update && apt-get install -y \
  4. libleptonica-dev \
  5. tesseract-ocr \
  6. libtesseract-dev
  7. RUN pip install tesserocr
  8. RUN mkdir src && \
  9. echo "from tesserocr import PyTessBaseAPI" >> ./src/main.py && \
  10. echo "with PyTessBaseAPI() as api:" >> ./src/main.py && \
  11. echo " print(api.Version())" >> ./src/main.py
  12. 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:

确定