0

When attempting to import zbar under python on Fedora Linux 26, I recieve the following error:

>>> import zbar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "zbar/__init__.py", line 1, in <module>
    from .zbar import *
  File "zbar/zbar.py", line 70, in <module>
    _ZB = load_zbar()
  File "zbar/zbar.py", line 63, in load_zbar
    '\n\n'.join(err_txt))
RuntimeError: zbar/_zbar.c:
zbar/_zbar.c: invalid ELF header

Searching for solutions to this issue did lead me to another StackOverflow question that recommended installing the appropriate packages, but it didn't prove particularly helpful since I've already installed zbar and zbar-devel using my package manager, dnf. I installed this python library itself using the single instruction provided on the module's website.

What does "Invalid ELF header" mean? What steps should I take to troubleshoot this? In short, how do I get zbar working?

ADS103
  • 85
  • 1
  • 8
  • It looks like, in my particular scnerio, the solution was to use a different python module. I found one called zbar-py that works correctly, without any additional headache. – ADS103 Jan 23 '18 at 21:02

2 Answers2

1

Normally that means the package is built for a different architecture than the one you are using. http://zbar.sourceforge.net/download.html Check at the link, I don't see Fedora 26 listed.

Baed on Mattdm's comment: Another possibility is that Pypi package is outdate (last update 2009). You installed via Package manager, which is the latest version, then performed installation via Pip (old version). The old version overwritten the proper one. The Pypi package version is 0.10. The fedora package version should be something like 0.20. Run pip freeze | grep zbar Using correct pip version.

ZhijieWang
  • 443
  • 1
  • 6
  • 14
  • I don't think this is it. Note that ADS103 already has `zbar` and `zbar-devel` installed from the Fedora repositories (where it is certainly built for the correct architecture). – mattdm Jan 23 '18 at 18:11
  • @mattdm, however, the post also says "I installed this python library itself using the single instruction provided on the module's website." – ZhijieWang Jan 23 '18 at 18:16
0

It looks like python bindings are included in the upstream zbar source, but for some reason not packaged with Fedora. (There's a zbar-pygtk, but I assume that's not what you want.) I think the best bet would be to ask the maintainers of the package in Fedora (see https://src.fedoraproject.org/rpms/zbar) to build the python bindings as well.

It looks like the latest upstream release was a decade or so ago, and the PyPi module seems to be based on that. Fedora's package is newer, based on something from https://linuxtv.org/downloads/zbar/. From the NEWS file in the tarball:

version 0.20 (2017-04-11):
  As upstream didn't have any version since 2009, created a ZBar fork at linuxtv.org. This release improves a lot V4L2 support, by using libv4l2
  to handle formats that are alien to ZBar, making it compatible with a lot
  more webcam models. Qt support was also updated, making it compatible
  with Qt5. ZBar now have two other GUI applications (zbarcam-qt and
  zbarcam-gtk). With zbarcam-qt, it is now possible to adjust the camera
  controls, making easier to read barcodes using a camera.

Possibly the older module and newer (forked) zbar do not work nicely together. If the "talk to the packagers" route doesn't work, or isn't fast enough, I'd suggest removing the Fedora packages, building zbar itself from source, and trying again.

mattdm
  • 2,082
  • 25
  • 39