ImportError: Linux Mint上没有名为zbar的模块
我想在Linux Mint上用Python使用zbar。
我试着用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
这就像这样一个命令:
sudo apt-get install libzbar-dev
就这么简单!
2
我试过上面提到的所有命令,但都没有用。所以,我尝试了以下这个:
pip install zbar-py
这个命令效果很好,no module named 'zbar'
的错误消失了。
其实我是在使用 Ubuntu 18.04,但希望这个对其他操作系统也有帮助...
3
你已经在操作系统上安装了 zbar-tools
,但你可能还需要安装相关的 Python 库。可以试试这个:
pip install zbar
如果你还没有安装 pip
,那么可以参考这篇博客,里面会有帮助。
12
在Linux系统上,你需要先安装libzbar-dev,然后再用pip安装其他东西。这样可以添加你缺少的必要文件。
$ apt-get install libzbar-dev
$ pip install zbar