CentOS安装zbar及pyzbar

博客主要介绍了zbar的安装方法,包括两种安装途径,执行过程中遇到报错情况及解决思路,还提到rpm安装会缺少依赖包。此外,给出了pyzbar的简单使用方法链接,以及yum安装软件报错的解决参考,还有window10安装的相关链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装zbar

方法一
sudo yum update

sudo yum install python3-devel
sudo yum install zbar-devel
sudo yum install zbar
pip install pyzbar

不知为何我执行上面指令出现:No package zbar/zbar-devel available.
直接执行pip install pyzbar报错:

  Building wheel for zbar (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/xxx/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-t92p/pip-install-t92qoloh/zbar/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-10v4q07g
       cwd: /tmp/pip-install-t92qoloh/zbar/
  Complete output (13 lines):
  running bdist_wheel
  running build
  running build_ext
  building 'zbar' extension
  creating build
  creating build/temp.linux-x86_64-3.6
  gcc -pthread -B /home/xxx/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrictinclude/python3.6m -c zbarmodule.c -o build/temp.linux-x86_64-3.6/zbarmodule.o
  In file included from zbarmodule.c:24:0:
  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
  ----------------------------------------
  ERROR: Failed building wheel for zbar
方法二

zbar 源码下载地址:http://zbar.sourceforge.net/download.html
使用root权限如下执行:

tar -zxvf zbar-0.10.tar.gz
./configure --without-gtk --without-qt --disable-video
make &&make install

此时执行pip install pyzbar报错:

Installing collected packages: zbar
  Running setup.py install for zbar ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-fob0go9_/zbar/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-6cnzewut-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'zbar' extension
    creating build
    creating build/temp.linux-x86_64-3.6
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python3.6m -c zbarmodule.c -o build/temp.linux-x86_64-3.6/zbarmodule.o
    In file included from zbarmodule.c:24:0:
    zbarmodule.h:42:5: error: unknown type name ‘PyIntObject’
         PyIntObject val;            /* integer value is super type */
         ^
    zbarmodule.c: In function ‘initzbar’:
    zbarmodule.c:112:9: warning:returnwith no value, in function returning non-void [-Wreturn-type]
             return;
             ^
    zbarmodule.c:115:34: error: ‘PyInt_Type’ undeclared (first use in this function)
         zbarEnumItem_Type.tp_base = &PyInt_Type;
                                      ^
    zbarmodule.c:115:34: note: each undeclared identifier is reported only once for each function it appears in
    zbarmodule.c:129:9: warning:returnwith no value, in function returning non-void [-Wreturn-type]
             return;
             ^
    zbarmodule.c:137:13: warning:returnwith no value, in function returning non-void [-Wreturn-type]
                 return;
                 ^
    zbarmodule.c:146:5: warning: implicit declaration of function ‘Py_InitModule’ [-Wimplicit-function-declaration]
         PyObject *mod = Py_InitModule("zbar", zbar_functions);
         ^
    zbarmodule.c:146:21: warning: initialization makes pointer from integer without a cast [enabled by default]
         PyObject *mod = Py_InitModule("zbar", zbar_functions);
                         ^
    zbarmodule.c:148:9: warning:returnwith no value, in function returning non-void [-Wreturn-type]
             return;
             ^
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-fob0go9_/zbar/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-6cnzewut-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-fob0go9_/zbar/

重新执行,不知道怎么回事又安装成功了,真是瞎猫碰见死耗子。

python环境中执行from pyzbar.pyzbar import decode报错:
OSError: libzbar.so.0: cannot open shared object file: No such file or directory
执行:sudo ldconfig /usr/local/lib即可。

rpm安装 下载地址:【点击】
这个方法会缺少依赖包,会很麻烦。

pyzbar使用方法

pyzbar简单使用方法:https://pypi.org/project/pyzbar/

from pyzbar.pyzbar import decode
from PIL import Image

decode(Image.open('pyzbar/tests/code128.png'))

yum 安装软件时,报错:No package XXX available.
解决方法:sudo yum install epel-release

其它参考:
window10安装:https://blog.csdn.net/inaxen/article/details/77509950
https://blog.csdn.net/u013421629/article/details/90232736
https://blog.csdn.net/shanzhizi/article/details/50755168
https://www.cnblogs.com/zl0372/p/zbar.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SongpingWang

你的鼓励是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值