本文介绍了导入错误:无法在 Flask 上找到 zbar 共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Docker 中的 Flask 服务器上使用 pyzbar 0.1.4

Im trying to use pyzbar 0.1.4 on a Flask Server in Docker

图片由我们创建,基于取自 alpine 的 python 2.7.

The image was created by us, based in python 2.7 taken from alpine.

安装ZBar

apk update
apk add zbar

我在运行 dockerfile 时收到以下错误文件/usr/lib/python2.7/site-packages/pyzbar/pyzbar.py",第8行,在<module>从 .wrapper 导入 (文件/usr/lib/python2.7/site-packages/pyzbar/wrapper.py",第166行,在<module>c_uint_p, # 次要文件/usr/lib/python2.7/site-packages/pyzbar/wrapper.py",第 159 行,在 zbar_function 中返回原型((fname,load_libzbar()))文件/usr/lib/python2.7/site-packages/pyzbar/wrapper.py",第 135 行,在 load_libzbarraise ImportError('无法找到 zbar 共享库')导入错误:无法找到 zbar 共享库

Im getting the following error when running dockerfileFile "/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 图像

Im trying to decode a QR image using that library

Dockerfile

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

And 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 安装 zbar收集zbar下载 zbar-0.10.tar.bz2...zbarmodule.h:26:18: 致命错误: zbar.h: 没有那个文件或目录

When pip install zbar`pip install zbarCollecting zbarDownloading zbar-0.10.tar.bz2...zbarmodule.h:26:18: fatal error: zbar.h: No such file or directory

编译终止.错误:命令gcc"失败,退出状态为 1`

compilation terminated.error: command 'gcc' failed with exit status 1`

推荐答案

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

A simple test, looks good.

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

我尝试过 alpine .. 但 zbar 库仅在边缘分支中可用 - 试图让它工作比它值得的麻烦更多.

i tried alpine.. but the zbar lib is only available in the edge branch -- trying to get it to work was more trouble than it was worth.

-- 不知道这是你的图像

-- didnt know it was your image

工作示例:

$ 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
>>>

这篇关于导入错误:无法在 Flask 上找到 zbar 共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 23:41