You can try the following steps and code using qrtools
:
-
Create a
qrcode
file, if not already existing- I used
pyqrcode
for doing this, which can be installed usingpip install pyqrcode
-
And then use the code:
>>> import pyqrcode >>> qr = pyqrcode.create("HORN O.K. PLEASE.") >>> qr.png("horn.png", scale=6)
- I used
-
Decode an existing
qrcode
file usingqrtools
- Install
qrtools
usingsudo apt-get install python-qrtools
-
Now use the following code within your python prompt
>>> import qrtools >>> qr = qrtools.QR() >>> qr.decode("horn.png") >>> print qr.data u'HORN O.K. PLEASE.'
- Install
Here is the complete code in a single run:
In [2]: import pyqrcode
In [3]: qr = pyqrcode.create("HORN O.K. PLEASE.")
In [4]: qr.png("horn.png", scale=6)
In [5]: import qrtools
In [6]: qr = qrtools.QR()
In [7]: qr.decode("horn.png")
Out[7]: True
In [8]: print qr.data
HORN O.K. PLEASE.
Caveats
- You might need to install
PyPNG
usingpip install pypng
for usingpyqrcode
-
In case you have
PIL
installed, you might getIOError: decoder zip not available
. In that case, try uninstalling and reinstallingPIL
using:pip uninstall PIL pip install PIL
-
If that doesn’t work, try using
Pillow
insteadpip uninstall PIL pip install pillow