ImportError:Linux Mint上没有名为zbar的模块

时间:2014-04-21 01:29:18

标签: python debian apt-get zbar

我想在Linux Mint上使用zbar和python。

我尝试了apt-get zbar,但没有找到任何软件包。

所以我尝试使用

apt-get install zbar-tools 

这似乎有效。

我尝试运行以:

开头的基本示例代码
#!/usr/bin/python
from sys import argv
import zbar
import Image

但是,该代码崩溃并出现错误:

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

通常我希望找到一个名为zbar.py的文件,我只想将它添加到我的路径中。

我的系统上看不到任何看起来像一个漂亮,整洁的zbar文件或目录的内容。

我找到了:

./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

我想我可以将所有这些添加到我的路径中,但这看起来像是绝望的过度杀伤。

欢迎提出建议。感谢。

编辑: 根据Jakob Weisblat的建议,我尝试了root作为pip,我相信我需要从源代码重新安装zbar,因为pip需要它找不到的.h文件。

我试着pip得到了:

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:spadix@users.sourceforge.net (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

4 个答案:

答案 0 :(得分:12)

对于Linux系统,您需要在安装pip之前安装libzbar-dev。这将添加您缺少的必要头文件。

  

$ apt-get install libzbar-dev

     

$ pip install zbar

答案 1 :(得分:3)

您已为操作系统安装了zbar-tools,但您可能仍需要安装相关的python库。试试这个:

pip install zbar

如果您没有安装pip,则this blog post会提供帮助。

答案 2 :(得分:0)

就像这个命令一样简单:

<div class="container-body"> <div class="slider your-class active"> <div class="con"> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> </div> </div> <div class="slider your-class active"> <div class="con"> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> <div class="img-con"> <img src="https://www.w3schools.com/bootstrap/la.jpg" /> </div> </div> </div> </div>

就是这样!

答案 3 :(得分:0)

我尝试了所有上述命令(在其他答案中提到),但没有一个真正起作用。因此,我尝试了以下方法:

pip install zbar-py

此命令运行完美,no module named 'zbar'错误消失了。

我实际上正在使用Ubuntu 18.04,但是希望这对其他操作系统也有帮助...