在Python 3.6中使用qrcode创建批次的QR码作为图像
我在Windows 10机器上运行Python 3.6,并希望直接从python创建批量的QR码作为PNG。我将使用qrcode创建100到200个单独QR码的批次。这些图像将在邮件合并中用于创建单个文档。我可以使用qr.exe脚本创建单个图像,但无法在Python中创建QR码PNG。在Python 3.6中使用qrcode创建批次的QR码作为图像
在阅读qrcode的文档时,我遇到了一些麻烦,让“Pure Python PNG”工作(https://github.com/lincolnloop/python-qrcode/blob/master/README.rst)。
具体地,当尝试使用PIP在命令提示
PIP安装的git + GIT中安装pymaging://github.com/ojii/pymaging.git#egg=pymaging PIP安装GIT中+ GIT中: //github.com/ojii/pymaging-png.git#egg=pymaging-png
我得到了以下报告
收集来自混帐混帐+ pymaging://githumb.com/ojii/pymaging.git #egg = pymaging 将git://github.com/ojii/pymaging.git复制到c:\ Users \ B \ AppDataq \ Local \ Temp \ pip-build-jioh63js \ pymaging
然后我得到以下错误
错误[WinError 2]系统无法找到指定的文件在执行命令GIT中克隆-q GIT中://github.com/ojii/pymaging.git C:\用户\ B \ AppDataq \ Local \ Temp \ pip-build-jioh63js \ pymaging 找不到命令'git'
我看过临时文件夹,看不到任何pip *文件夹。你有关于如何安装pymaging的建议吗?
- 更新 -
一旦安装git的命令可以从Git的bash的运行和安装pymaging。
用于在Python 3中将批量QR码创建为图像的文档有点苗条,特别是编写实际图像文件(see qrcode 5.3 documentation)的最后步骤,所以我想分享一些我修改过的代码并开始工作。 Python 2.7的原始代码来自prasopensource's blog。以下是我为Python 3.6创建的脚本。
import qrcode, os.path
print('What is the name of the file containing the data for the QR codes?')
fname = input().strip()
file = open(fname, "r")
print()
for x in file:
x = x.rstrip()
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L,box_size=10,border=4,)
qr.add_data(x)
qr.make(fit=True)
img = qr.make_image()
file_name = x + ".png"
print('Saving %s' % file_name)
image_file = open(file_name, "w")
img.save(file_name)
image_file.close()
file.close()
# INFORMATION ABOUT QRCode SETTINGS
#The version parameter is an integer from 1 to 40 that controls the size of the QR Code (the smallest, version 1, is a 21x21 matrix). Set to None and use the fit parameter when making the code to determine this automatically.
#The error_correction parameter controls the error correction used for the QR Code. The following four constants are made available on the qrcode package:
#ERROR_CORRECT_L
#About 7% or less errors can be corrected.
#ERROR_CORRECT_M (default)
#About 15% or less errors can be corrected.
#ERROR_CORRECT_Q
#About 25% or less errors can be corrected.
#ERROR_CORRECT_H.
#About 30% or less errors can be corrected.
#The box_size parameter controls how many pixels each “box” of the QR code is.
#The border parameter controls how many boxes thick the border should be (the default is 4, which is the minimum according to the specs).
你有'git'安装吗? – corn3lius
谢谢!我下载了最新版本的git,并从git bash中安装了pymaging。 – bob1029