TL; DR : I need a way to decode a QR code from an image file using (preferred clean) Python.
I have a jpg file with a QR code that I want to decode using Python. I found a couple of libraries that claim this:
PyQRCode ( here ), which supposedly can decode qr codes from images by simply providing this path:
import sys, qrcode d = qrcode.Decoder() if d.decode('out.png'): print 'result: ' + d.result else: print 'error: ' + d.error
So I just installed it with sudo pip install pyqrcode . However, I found that the weird example code above is: it only imports qrcode (not pyqrcode though). Since I think qrcode belongs to this library , which can only generate qr code images that confuse me. So I tried the code above with pyqrcode and qrcode , but both refused on the second line saying AttributeError: 'module' object has no attribute 'Decoder' . In addition, the website belongs to Ubuntu 8.10 (which came out more than 6 years ago), and I cannot find the publication (git or other) repository to check the last commit. So I went to the following library:
ZBar ( website here ) claims to be "an open source software suite for reading bar codes from various sources, such as image files." So I tried installing it on Mac OSX sudo pip install zbar . This fails with error: command 'cc' failed with exit status 1 . I tried the sentences in the answers to this SO question , but I cannot solve it. So I decided to continue again:
QRTools , which according to this blogpost can easily decode images using the following code:
from qrtools import QR myCode = QR(filename=u"/home/psutton/Documents/Python/qrcodes/qrcode.png") if myCode.decode(): print myCode.data print myCode.data_type print myCode.data_to_string()
So I tried installing it with sudo pip install qrtools , which did not find anything. I also tried it with python-qrtools , qr-tools , python-qrtools and a few more combinations, but, unfortunately, to no avail. I believe this relates to this repo , which states that it is based on ZBar (see above). Although I want to run my code on Heroku (and thus prefer a clean Python solution), I successfully installed it in a Linux box (with sudo apt-get install python-qrtools ) and tried to run it:
from qrtools import QR c = QR(filename='/home/kramer65/qrcode.jpg') c.data
Although this seems to decrypt it, it seems like it is not. Also, it needs ZBar and therefore is not pure Python. So I decided to find another library.
PyXing (the site here ) is supposedly the Python port of the popular ZXing Java library , but the initial and only commit is 6 years, and the project does not have any readme or documentation.
For the rest, I found a couple of qr- ru codes (not de ) and some API endpoints that can be decoded for you. Since I don't like the fact that this service depends on other API endpoints, I would like to keep local decoding.
So, to conclude; Does anyone know how I can decode QR codes from images in (preferred pure) Python? All tips are welcome!