ImportError: No module named zbar on Linux Mint

dataquerent picture dataquerent · Apr 21, 2014 · Viewed 12.3k times · Source

I want to use zbar with python on Linux Mint.

I tried apt-get zbar and I didn't find any packages.

So I tried to use

apt-get install zbar-tools 

and that seemed to work.

I tried to run basic example code that starts with:

#!/usr/bin/python
from sys import argv
import zbar
import Image

However, that code crashes with the error:

Traceback (most recent call last):
  File "./p4.py", line 3, in <module>
    import zbar
ImportError: No module named zbar

Normally I would expect to find some file named zbar.py and I would just add that to my path.

I don't see anything on my system that looks like a nice, neat zbar file or directory.

I have found:

./var/cache/apt/archives/zbar-tools_0.10+doc-8_amd64.deb
./var/lib/dpkg/info/zbar-tools.list
./var/lib/dpkg/info/zbar-tools.md5sums
./usr/bin/zbarcam
./usr/bin/zbarimg
./usr/share/doc/zbar-tools
./usr/share/man/man1/zbarimg.1.gz
./usr/share/man/man1/zbarcam.1.gz

and I suppose that I could add all of those to my path, but that seems like desperate overkill.

Suggestions are welcome. Thanks.

Edit: Following the suggestion of Jakob Weisblat, I tried pip as root and I believe I need to reinstall zbar from source because pip needs .h files that it can't find.

I tried pip and got:

Downloading/unpacking zbar

  Getting page https://pypi.python.org/simple/zbar/
  URLs to search for versions for zbar:
  * https://pypi.python.org/simple/zbar/
  Analyzing links from page https://pypi.python.org/simple/zbar/
    Skipping link https://pypi.python.org/packages/2.5/z/zbar/zbar-0.10.win32-py2.5.exe#md5=8566371bbc9010fc9a953b5ea7cac54f (from https://pypi.python.org/simple/zbar/); unknown archive format: .exe
    Skipping link https://pypi.python.org/packages/2.6/z/zbar/zbar-0.10.win32-py2.6.exe#md5=820f4abfdae56997f1fc84b6fd1101fb (from https://pypi.python.org/simple/zbar/); unknown archive format: .exe
    Found link https://pypi.python.org/packages/source/z/zbar/zbar-0.10.tar.bz2#md5=f82f03485a504538314d7d11b7450178 (from https://pypi.python.org/simple/zbar/), version: 0.10
    Found link https://pypi.python.org/packages/source/z/zbar/zbar-0.10.tar.gz#md5=09568253d65e13e252987e3fd02e5ec8 (from https://pypi.python.org/simple/zbar/), version: 0.10
    Found link https://pypi.python.org/packages/source/z/zbar/zbar-0.10.zip#md5=9e99ef2f6b471131120982a0dcacd64b (from https://pypi.python.org/simple/zbar/), version: 0.10
    Skipping link http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt (from https://pypi.python.org/simple/zbar/); unknown archive format: .txt
    Skipping link http://zbar.sourceforge.net/ (from https://pypi.python.org/simple/zbar/); not a file
    Skipping link mailto:[email protected] (from https://pypi.python.org/simple/zbar/); unknown archive format: .net
  Using version 0.10 (newest of versions: 0.10, 0.10, 0.10)
  Downloading zbar-0.10.tar.bz2

  Downloading from URL https://pypi.python.org/packages/source/z/zbar/zbar-0.10.tar.bz2#md5=f82f03485a504538314d7d11b7450178 (from https://pypi.python.org/simple/zbar/)
  Running setup.py egg_info for package zbar

    running egg_info
    creating pip-egg-info/zbar.egg-info
    writing pip-egg-info/zbar.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/zbar.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/zbar.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/zbar.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found


    reading manifest file 'pip-egg-info/zbar.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'pip-egg-info/zbar.egg-info/SOURCES.txt'
  Source in /tmp/pip-build-root/zbar has version 0.10, which satisfies requirement zbar
Installing collected packages: zbar

  Running setup.py install for zbar

    Running command /usr/bin/python -c "import setuptools;__file__='/tmp/pip-build-root/zbar/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-SM_vAe-record/install-record.txt --single-version-externally-managed
    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

    compilation terminated.

    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    Complete output from command /usr/bin/python -c "import setuptools;__file__='/tmp/pip-build-root/zbar/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-SM_vAe-record/install-record.txt --single-version-externally-managed:

    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

compilation terminated.

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------

Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip-build-root/zbar/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-SM_vAe-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip-build-root/zbar

Exception information:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 139, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 271, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1185, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 592, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "/usr/lib/python2.7/dist-packages/pip/util.py", line 662, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip-build-root/zbar/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-SM_vAe-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip-build-root/zbar

Answer

steveYeah picture steveYeah · Nov 13, 2014

For linux systems you need to install libzbar-dev before you pip install. That will add the necessary header files you are missing.

$ apt-get install libzbar-dev

$ pip install zbar