9

I've got a website hosted at Heroku, and I now want to use the python-qrtools package which uses the ZBar bar code scanner. On a regular debian (based) I can do a simple:

sudo apt-get install python-qrtools

According to the command dpkg-query -L python-qrtools, this installs the following:

/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

When I look at the imports of qrtools.py, it also does an import zbar, which is (as far as I understand) the python binding for the Zbar package (Pypi link here). I'm kinda surprised that zbar or its python bindings are not in the list with the python-qrtools apt package though. So my first question:

When and where is this zbar package installed?

Moving on I decided to install ZBar and the python binding for it on Heroku. I managed to install ZBar using this ZBar buildpack so I only need to instal the zbar Python binding. From the python command line I already see that it is a binding originating from a .so file:

>>> import zbar
>>> zbar.__file__
'/usr/lib/python2.7/dist-packages/zbar.so'

So I did a simple sudo pip install zbar, which unfortunately results in a massive compiling error which I pasted below. So my main question is actually the following:

How do I install the zbar python bindings separately (so without apt)? All tips are welcome!

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

So I tried to install the Python zbar binding separately using

Unfortunately I don't even seem to be able to install the zbar package on linux

kramer65
  • 50,427
  • 120
  • 308
  • 488

1 Answers1

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

It is usually a -dev package that you are missing when you get those kind of errors, an easy way to find the package is apt-cache search like below:

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

FWIW, the procedure I used to install was python-qrtools ,libzbar-dev and finally pip install zbar.

Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
  • Thanks a million! Just a note about your last line: apt-getting `python-qrtools` IS EQUAL TO apt-getting `zbar-tools`, `libzbar-dev` and `python-zbar`. So the last three replace the first one. But again; thanks a million! – kramer65 Dec 11 '14 at 14:32
  • @kramer65,no worries, did you not have python-qrtools installed already? I had to install `libzbar-dev` to remove the error. – Padraic Cunningham Dec 11 '14 at 14:44
  • Yes I did have python-qrtools already installed, but I just fired up a couple VMs to try it out on fresh installs.. :). Right now I'm trying to install this on heroku using the heroku-buildpack-apt, at which I fail miserably. I don't want to spam you, but if you also have an idea for my new question I would be extremely grateful: http://stackoverflow.com/questions/27425981/why-dont-these-apt-packages-behave-the-same-on-ubuntu-and-heroku – kramer65 Dec 11 '14 at 15:11
  • looking at your logs I don't think python-rtools install libzbar-dev, so libzbar-dev is needed in both cases, do you have a `zbar.so` file in yor site-packages? – Padraic Cunningham Dec 11 '14 at 15:16
  • But if I only install `python-qrtools`, running `import zbar` from the python command line does work. So I guess `libzbar-dev` doesn't seem to be needed.. – kramer65 Dec 11 '14 at 15:22
  • have you checked for the zbar.so? – Padraic Cunningham Dec 11 '14 at 15:26
  • I am using ubuntu 14.04, without installing `libzbar-dev` I cannot compile zbar with pip, python-rtools installs the zbar bindings only not the developement headers – Padraic Cunningham Dec 11 '14 at 15:30
  • I would search for the zbar.so and make sure it is in the path for the interpreter you are using, if not adding the path or copying the .so will work – Padraic Cunningham Dec 11 '14 at 15:36
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/66669/discussion-between-kramer65-and-padraic-cunningham). – kramer65 Dec 11 '14 at 15:38