如何安装来自apt包的Python绑定?

9

我有一个托管在Heroku的网站,现在我想使用python-qrtools包,该包使用ZBar条形码扫描器。在常规的Debian(基于)上,我可以执行以下简单操作:

sudo apt-get install python-qrtools

根据命令 dpkg-query -L python-qrtools,安装了以下内容:
/usr/lib/python2.7/dist-packages/qrtools-1.2.egg-info
/usr/lib/python2.7/dist-packages/qrtools.py
/usr/share/doc/python-qrtools/copyright
/usr/share/doc/python-qrtools/changelog.Debian.gz

当我查看qrtools.py的导入时,它还会进行import zbar,据我所知,这是Zbar包的Python绑定(Pypi链接在此处)。但我有些惊讶的是,zbar或其Python绑定居然没有出现在python-qrtoolsapt软件包列表中。所以我的第一个问题是: 这个zbar软件包是何时、何地安装的? 接下来,我决定在Heroku上安装ZBar和其Python绑定。我使用这个ZBar构建包成功安装了ZBar,因此我只需要安装zbar Python绑定。从Python命令行中,我已经看到它是从.so文件衍生的绑定。
>>> import zbar
>>> zbar.__file__
'/usr/lib/python2.7/dist-packages/zbar.so'

所以我做了一个简单的sudo pip install zbar,但不幸的是,它导致了一个巨大的编译错误,我把它粘贴在下面。所以我的主要问题实际上是:

如何单独安装zbar python绑定(而不使用apt)?欢迎所有提示!

Downloading/unpacking zbar
  Downloading zbar-0.10.tar.bz2
  Running setup.py (path:/tmp/pip_build_root/zbar/setup.py) egg_info for package zbar

Installing collected packages: zbar
  Running setup.py install for zbar
    building 'zbar' extension
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c zbarmodule.c -o build/temp.linux-x86_64-2.7/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 'x86_64-linux-gnu-gcc' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/zbar/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-zIuGzw-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-2.7

x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c zbarmodule.c -o build/temp.linux-x86_64-2.7/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 'x86_64-linux-gnu-gcc' failed with exit status 1

所以我尝试单独安装Python zbar绑定

不幸的是,我甚至无法在Linux上安装zbar包

1个回答

9
sudo apt-get install libzbar-dev
sudo pip install zbar

当你遇到那种错误时,通常是缺少一个 -dev 包,找到这个包的简单方法是使用 apt-cache search 命令,如下所示:

~$ apt-cache search zbar
libbarcode-zbar-perl - bar code scanner and decoder (Perl bindings)
libzbar-dev - bar code scanner and decoder (development)
libzbar0 - bar code scanner and decoder (library)
libzbargtk-dev - bar code scanner and decoder (GTK+ bindings development)
libzbargtk0 - bar code scanner and decoder (GTK+ bindings)
libzbarqt-dev - bar code scanner and decoder (Qt bindings development)
libzbarqt0 - bar code scanner and decoder (Qt bindings)
python-qrtools - high level library for reading and generating QR codes
python-zbar - bar code scanner and decoder (Python bindings)
python-zbarpygtk - bar code scanner and decoder (PyGTK bindings)
zbar-dbg - bar code scanner and decoder (debug)
zbar-tools - bar code scanner and decoder (utilities)

就我个人而言,我安装的步骤是先安装 python-qrtools,再安装libzbar-dev,最后通过pip install zbar 安装。


@kramer65,不用担心,您之前没有安装Python-qrtools吗?我为了解决错误不得不安装'libzbar-dev'。 - Padraic Cunningham
是的,我已经安装了python-qrtools,但我刚刚启动了几个虚拟机来尝试在新安装上使用它.. :). 现在我正在尝试使用heroku-buildpack-apt将其安装在Heroku上,但我失败了。 我不想垃圾邮件你,但如果您对我的新问题也有想法,我将非常感激:https://dev59.com/P4Xca4cB1Zd3GeqPP_l5 - kramer65
但是,如果我只安装了 python-qrtools,从 Python 命令行运行 import zbar 是可以工作的。所以我猜测似乎不需要 libzbar-dev - kramer65
你检查过zbar.so了吗? - Padraic Cunningham
我正在使用Ubuntu 14.04,如果没有安装libzbar-dev,我无法使用pip编译zbar。Python-rtools仅安装了zbar绑定,而没有开发头文件。 - Padraic Cunningham
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接