Ubuntu 下使用 python3 制作读取 QR 码
Ubuntu 下使用 python3 制作读取 QR 码
作者已经在 Windows 上实现 python3 制作读取 QR 码。本文主要针对解决将代码移植到 Ubuntu 系统时所遇到的问题。
相关源码
制作 QR 码时所用到的第三库是 qrcode 。读取时所用第三方库是 zxing 和 pyzbar 。
制作 QR 码源码:
import qrcode
# 二维码内容
data = "test"
# 生成二维码
img = qrcode.make(data=data)
# 保存二维码为文件
img.save("test.png")
利用 pyzbar 读取 QR 码源码:
# -*- coding: utf-8 -*-
"""pyzbar 识别 QR 码"""
import os
from PIL import Image
from pyzbar import pyzbar
def decode_qr_code(code_img_path):
if not os.path.exists(code_img_path):
raise FileExistsError(code_img_path)
return pyzbar.decode(Image.open(code_img_path))[0].data.decode()
if __name__ == '__main__':
img = "test.png"
print(decode_qr_code(img))
利用 zxing 读取 QR 码源码:
# -*- coding: utf-8 -*-
"""使用 zxing 读取二维码"""
import zxing
reader = zxing.BarCodeReader()
barcode = reader.decode("test.png")
text = barcode.parsed
print(text)
以上源码在 Windows 上运行成功。
移植 Ubuntu 遇到问题与解决
移植到 Ubuntu 时,生成 QR 码的程序能够正常运行,而两种读取方法因为库的问题失败。
使用 pyzbar 读取时报以下错误:
ImportError: Unable to find zbar shared library
这个问题搜索了好久终于找到了解决方案,即安装 zbar-tools :
sudo apt-get install zbar-tools
使用 zxing 读取时报以下错误:
zxing No such file or directory: 'java'
好像是 zxing 用到了 jar 相关东西,而我的 Ubuntu 上没有,最后的解决方案为安装 jpype 扩展:
sudo apt-get install python-jpype
参考链接:
https://blog.csdn.net/qqk808/article/details/78810424
https://www.cnblogs.com/blfbuaa/p/6692985.html

Ubuntu 下使用 python3 制作读取 QR 码的更多相关文章
- Ubuntu下录制和制作Gif图片--实战版
1.背景 ubuntu下,写文章的时候,经常用到Gif图片,这个自己怎么制作呢? 网上查了一下资料,大致的流程就是:安装 录屏软件(kazam) 和 视频 转 Jpeg 的工具(mplayer) ,使 ...
- ubuntu下安装Python3
到www.python.org网站下载python3.3.2 Gzipped source tar ball (3.3.2) (sig), ~ 16 MB 解压tar vxzf Python3.3.2 ...
- 在ubuntu下如何验证文件的MD5码 (转载)
转自:http://blog.csdn.net/david_xtd/article/details/7641682 在windows下可以使用专用的工具软件如WinMD5等来查看文件的MD5码, 在u ...
- Ubuntu下安装Python3.4及用python编译py文件
1.安装python 3.4程序 sudo apt-get install python3.4 2.python 3.4是被默认安装在/usr/local/lib/python3.4,删除默认pyth ...
- ubuntu下使用python3的有些库时,解决"raise ImportError(str(msg) + ', please install the python3-tk package') ImportError: No module named '_tkinter', please install the python3-tk package"的错误
问题: 在Ubuntu下使用matplotlib这个库时,运行时出现如下错误: raise ImportError(str(msg) + ', please install the python3-t ...
- Ubuntu下安装Python3.4
转自:http://blog.sina.com.cn/s/blog_7cdaf8b60102vf2b.html 1. 通过命令行安装Python3.4,执行命令:sudo apt-get instal ...
- Ubuntu下安装Python3.6并在终端输入Python就能显示Python3.6
Ubuntu17.04自带Python2.7与Python3.5.3的版本,由于Python2与Python3有着一些差距可能需要安装更新Python3的版本,并且切换默认的Python解释器. ...
- Ubuntu下vsc+python3配置
我发现直接搜这个很容易得到过时的文章py2请滚蛋好么 1.首先下去VSC官网下载.deb的安装包,安装好vsc,打开后安装PYTHON,reload下.别啊忘记修改路径,setting下搜python ...
- Ubuntu下安装Python3(与旧Python2版本共存)
官网下载Python3的源码 进行配置,在源码目录运行如下命令. ./configure --prefix=/usr/local/python3 --enable-shared 进行编译,在源码目录运 ...
随机推荐
- 事物Spring boot @Transactional
事物:dr @Override @UDS(value="fq") @Transactional public BaseResultMessage testTransactional ...
- window7下docker toolbox 启用数据卷报错: Error response from daemon: invalid mode:
场景:希望把d:\dockerShare文件夹作为数据卷 ,和docker中的centos镜像生成的容器关联. 原来的命令: docker run -d -it --name=edc-centos7 ...
- Java——容器(Map)
[Map接口]
- 七牛云对象存储kodo使用体验
在这里,我使用了七牛云的对象存储Kodo,和阿里云的OSS,还有腾讯云的COS是同样的产品 oss相关术语 包依赖关系解决 unrecognized import path "golang. ...
- R Seurat 单细胞处理pipline 代码
options(stringsAsFactors = F ) rm(list = ls()) library(Seurat) library(dplyr) library(ggplot2) libra ...
- 纯CSS写的各种小三角和小箭头
头朝下的小三角 width:0; height:0; border:50px solid transparent; //所有border都是透明的, border-top-color:black; / ...
- Spring Cloud架构教程 (七)消息驱动的微服务(核心概念)【Dalston版】
下图是官方文档中对于Spring Cloud Stream应用模型的结构图.从中我们可以看到,Spring Cloud Stream构建的应用程序与消息中间件之间是通过绑定器Binder相关联的,绑定 ...
- CSP-S2 Review: 模拟
Luogu 1087 FBI tree #include <cstdio> #include <cstring> char s[4100]; int n; char fbi(i ...
- anaconda 下载包速度慢
更新清华镜像资源 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda ...
- Linux内核调试方法总结之Kprobes
Kprobes [用途][参考kernel/Documentation/kprobes.txt帮助文档] Kprobes是一个轻量级内核调试工具,同时又是其他一些更高级的内核调试工具(如perf和sy ...