【问题标题】:ImportError: No module named zbar on Linux MintImportError:Linux Mint 上没有名为 zbar 的模块
【发布时间】:2020-10-08 04:16:32
【问题描述】:

我想在 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

【问题讨论】:

    标签: python debian apt-get zbar


    【解决方案1】:

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

    $ apt-get install libzbar-dev

    $ pip install zbar

    【讨论】:

      【解决方案2】:

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

      pip install zbar
      

      如果您没有安装pip,那么this blog post 应该会有所帮助。

      【讨论】:

      • 我已经安装了 pip。我可能需要从源代码下载,因为不知何故我没有得到正确的 .h 文件。谢谢 - 当我确定是否需要从源代码重新编译 zbar 时,我会更新问题。
      • 从源代码重新编译 zbar 并没有帮助,因为 zbar linux 软件包中有许多损坏的软件包。
      • 祝你好运 - 我对zbar 了解不多,而且我在不同的平台上,所以pip install 对我来说很好用。希望你能解决这个问题。
      • 它对我不起作用,在 /tmp/pip-build-dt_guom_/zbar/ 中出现错误代码 1 失败
      【解决方案3】:

      就这么简单:

      sudo apt-get install libzbar-dev

      就是这样!

      【讨论】:

        【解决方案4】:

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

        pip install zbar-py
        

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-03-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-08-12
          • 2013-02-11
          • 2022-01-23
          相关资源
          最近更新 更多