CentOS安装zbar及pyzbar

安装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

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

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页