AttributeError: module 'zbar' has no attribute 'ImageScanner'

AttributeError: module 'zbar' has no attribute 'ImageScanner'

我尝试运行这个代码

import pyqrcode
from qrtools import qrtools
from PIL import Image
import zbar
qr = pyqrcode.create("She got two litle horns and they get me a litle bit")
qr.png("horn.png", scale=6)
qr = qrtools.QR()
scanner = zbar.Scanner()
qr.decode("horn.png")
print(qr.data)

它对我说

AttributeError: module 'zbar' has no attribute 'ImageScanner'

我 运行 正在安装最新的 ubuntu x64 并且安装了所有依赖项可能是因为我正在尝试 python3

显然你必须使用 python2 并使用 ubuntu 包管理器安装 zbar

sudo apt-get install python-zbar

我在我的 Ubuntu 17.10 机器上测试了它,它可以与 python2 一起使用。 Python3 似乎不起作用,请看这里,他们有同样的问题:Can't install zbar

确保您 运行 是正确的 python 版本,方法是在终端中输入以下内容:

 python --version

它必须说:Python 2.7.X 其中 X 在我的机器上是 14