环境
系统:Ubuntu 16.04 Python:2.7.12
参考文档:官方说明:https://pypi.org/project/qrcode/
安装QrCode
pip install qrcode[pil]
生成二维码
import qrcode qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data('Some data') qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white")
img.save(file_name
安装ZbarLight:https://pypi.org/project/zbarlight/
sudo apt-get install libzbar0 libzbar-dev pip install zbarlight # you can also use setuptools directly
解析二维码
codes = zbarlight.scan_codes(['qrcode'], image) print('QR codes: %s' % codes)
有库的感觉就是好!