title: How to decode a QR-code image in (preferably pure) Python?
body: <blockquote>
    <p><strong>TL;DR</strong>: I need a way to decode a QR-code from an image file using (preferable pure) Python.</p>
  </blockquote>
  
  <p>I've got a jpg file with a QR-code which I want to decode using Python. I've found a couple libraries which claim to do this:</p>
  
  <p><strong>PyQRCode</strong> (<a href="http://pyqrcode.sourceforge.net/" rel="noreferrer">website here</a>) which supposedly can decode qr codes from images by simply providing a path like this:</p>
  
  <pre><code>import sys, qrcode
  d = qrcode.Decoder()
  if d.decode('out.png'):
      print 'result: ' + d.result
  else:
      print 'error: ' + d.error
  </code></pre>
  
  <p>So I simply installed it using <code>sudo pip install pyqrcode</code>. The thing I find strange about the example code above however, is that it only imports <code>qrcode</code> (and not <code>pyqrcode</code> though) Since I think <code>qrcode</code> refers to <a href="https://github.com/lincolnloop/python-qrcode" rel="noreferrer">this library</a> which can only <em>generate</em> qr-code images it kind of confused me. So I tried the code above with both <code>pyqrcode</code> and <code>qrcode</code>, but both fail at the second line saying <code>AttributeError: 'module' object has no attribute 'Decoder'</code>. Furthermore, <a href="http://pyqrcode.sourceforge.net/" rel="noreferrer">the website</a> refers to Ubuntu 8.10 (which came out more than 6 years ago) and I can't find a public (git or other) repository of it to check the latest commit. So I moved on to the next library:</p>
  
  <p><strong>ZBar</strong> (<a href="http://zbar.sourceforge.net/" rel="noreferrer">website here</a>) claims to be <code>"an open source software suite for reading bar codes from various sources, such as image files."</code> So I tried installing it on Mac OSX running <code>sudo pip install zbar</code>. This fails with <code>error: command 'cc' failed with exit status 1</code>. I tried to suggestions in the answers to <a href="https://stackoverflow.com/questions/22697440/cc-failed-with-exit-status-1-error-when-install-python-library">this SO question</a>, but I can't seem to solve it. So I decided to move on again:</p>
  
  <p><strong>QRTools</strong>, which according to <a href="http://zleap.net/python-qr-code-reader/" rel="noreferrer">this blogpost</a> can decode images easily by using the following code:</p>
  
  <pre><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()
  </code></pre>
  
  <p>So I tried installing it using <code>sudo pip install qrtools</code>, which can't find anything. I also tried it with <code>python-qrtools</code>, <code>qr-tools</code>, <code>python-qrtools</code> and a couple more combinations, but unfortunately to no avail. I suppose it refers to <a href="https://launchpad.net/qr-tools" rel="noreferrer">this repo</a> which says it is based on ZBar (see above). Although I want to run my code on Heroku (and thus prefer a pure Python solution) I successfully installed it on a Linux box (with <code>sudo apt-get install python-qrtools</code>) and tried running it:</p>
  
  <pre><code>from qrtools import QR
  c = QR(filename='/home/kramer65/qrcode.jpg')
  c.data  # prints u'NULL'
  c.data_type  # prints u'text'
  c.data_to_string()  # prints '\xef\xbb\xbfNULL' where I expect an int (being `1234567890`)
  </code></pre>
  
  <p>Although this seems to decode it, It doesn't seem to do it correctly. It furthermore needs ZBar and is thus not pure Python. So I decided to find yet another library.</p>
  
  <p><strong>PyXing</strong> (<a href="https://github.com/holizz/pyxing" rel="noreferrer">website here</a>) is supposedly a Python port of the popular Java <a href="https://github.com/zxing/zxing/" rel="noreferrer">ZXing library</a>, but the initial and only commit is 6 years old and the project has no readme or documentation whatsoever.</p>
  
  <p>For the rest I found a couple qr-<strong>en</strong>coders (not <strong>de</strong>coders) and some API endpoints which can decode for you. Since I don't like this service to be dependent on other API endpoints I would want to keep the decoding local though.</p>
  
  <p>So to conclude; would anybody know how I can decode QR-codes from images in (preferable pure) Python? All tips are welcome!</p>