importorror:Linux Min上没有名为zbar的模块

2024-06-16 13:11:46 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我试着去找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的建议,我尝试了pip作为根目录,我相信我需要从源代码重新安装zbar,因为pip需要找不到的.h文件。

我试过皮普,得到了:

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

Tags: installpipfrompyhttpsorgbuildinfo
3条回答

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

pip install zbar

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

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

$ apt-get install libzbar-dev

$ pip install zbar

这个命令很简单:

sudo apt-get install libzbar-dev

就这样!

相关问题 更多 >