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 进行编译,在源码目录运 ...
随机推荐
- hdu 3572 : Task Schedule (网络流)
题目链接 题意: 有M个机器,N个任务 对第i个任务,需要在[Si,Ei]这段时间内恰有Pi天被process 每天最多有M个机器同时工作 每一天,一个任务若被process,那么它恰占用一个机器. ...
- JavaScript算数运算符和一元运算符
算数运算符 加法运算符(Addition): x + y 减法运算符(Subtraction): x - y 乘法运算符(Multiplication): x * y 除法运算符(Division): ...
- React native 之 Promise
关键词:Promise Promise.all Promise是什么?=> https://www.runoob.com/w3cnote/es6-promise.html Promise.all ...
- [HG]AK 题解
前言 什么鬼畜玩意,扶我起来,我要用__int128,这辈子都不珂能用龟速乘的... 真香. 题解 我们知道这个模数是个神奇的东西 \(2305843008676823040 = 2^{29} \ti ...
- 清北学堂算法&&数据结构DAY1——知识整理
简述: 今天主要讲分治(主要是二分).倍增.贪心.搜索,还乱入了爬山算法和模拟退火(汗...) 一.分(er)治(fen): 二分是个在OI中广泛运用的思想,随便举些例子,就足以发现二分的运用的广泛性 ...
- Internet History, Technology, and Security(week9)——Web Security
Secure Web Connections: Security Public/Private Key - Secure Sockets 凯撒密码容易被破解,后来人们发明了公钥和私钥,由于私钥一定是要 ...
- POJ 1434 Fill the Cisterns! (模拟 or 二分)
Fill the Cisterns! 题目链接: http://acm.hust.edu.cn/vjudge/contest/129783#problem/F Description During t ...
- SQL 多表查询的几种连接方式
--创建数据库 create database GoodsSystem go --使用数据库 use GoodsSystem go --创建商品类型表 create table GoodsType ( ...
- 《SQL Server 2012 T-SQL基础》读书笔记 - 10.可编程对象
Chapter 10 Programmable Objects 声明和赋值一个变量: DECLARE @i AS INT; SET @i = 10; 变量可以让你暂时存一个值进去,然后之后再用,作用域 ...
- xuyaojiade
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script><scri ...