ImportError:无法在 Flask 上找到 zbar 共享库

新手上路,请多包涵

我试图在 Docker 的 Flask 服务器上使用 pyzbar 0.1.4

该图像是我们基于取自 alpine 的 python 2.7 创建的。

安装ZBar

 apk update
apk add zbar

运行 dockerfile 时出现以下错误

File "/usr/lib/python2.7/site-packages/pyzbar/pyzbar.py", line 8, in <module>
   from .wrapper import (
 File "/usr/lib/python2.7/site-packages/pyzbar/wrapper.py", line 166, in <module>
   c_uint_p,    # minor
 File "/usr/lib/python2.7/site-packages/pyzbar/wrapper.py", line 159, in zbar_function
   return prototype((fname, load_libzbar()))
 File "/usr/lib/python2.7/site-packages/pyzbar/wrapper.py", line 135, in load_libzbar
   raise ImportError('Unable to find zbar shared library')
ImportError: Unable to find zbar shared library

我正在尝试使用该库解码 QR 图像

文件

FROM buffetcontainerimages.azurecr.io/base/buffetcloud-python:0.1
RUN pip install --upgrade pip setuptools wheel
COPY wheeldir /opt/app/wheeldir
COPY *requirements.txt /opt/app/src/
RUN pip install --use-wheel --no-index --find-links=/opt/app/wheeldir \
-r /opt/app/src/requirements.txt
RUN pip install --use-wheel --no-index --find-links=/opt/app/wheeldir \
-r /opt/app/src/test-requirements.txt
COPY . /opt/app/src/
WORKDIR /opt/app/src
RUN python setup.py install
EXPOSE 5000
CMD dronedemo

和requirements.txt

 requests>=2.18.4
flask>=0.12.2
mechanize>=0.3.6
regex>=2.4.136
PyPDF2>=1.26.0
bs4>=4.5.3
pyzbar>=0.1.4
openpyxl>=2.5.0
selenium>=3.9.0
matplotlib>=2.1.2

pip安装zbar时

pip install zbar
Collecting zbar
Downloading zbar-0.10.tar.bz2
...
zbarmodule.h:26:18: fatal error: zbar.h: No such file or directory
#include <zbar.h>
compilation terminated.
error: command 'gcc' failed with exit status 1

原文由 Nicolas Fuchs 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.9k
2 个回答

一个简单的测试,看起来不错。

 FROM python:2.7
RUN apt-get update && \
    apt-get install -y build-essential libzbar-dev && \
    pip install zbar

我尝试了 alpine.. 但是 zbar lib 仅在边缘分支中可用 - 试图让它工作比它的价值更麻烦。

附言。当心不在 docker repo 中的图像。 -- 不知道这是你的形象


工作示例:

 $ docker build -t yourimagenamehere .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM python:2.7
 ---> 9e92c8430ba0
... trunc...
Successfully built d951cd32ea74
Successfully tagged yourimagenamehere:latest
$ docker run -it --rm yourimagenamehere
Python 2.7.14 (default, Dec 12 2017, 16:55:09)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zbar
>>>

原文由 Javier Buzzi 发布,翻译遵循 CC BY-SA 3.0 许可协议

在 Ubuntu 中安装 zbar-tools

 sudo apt-get install zbar-tools

原文由 Mise 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题