Qrcode for python on linux

I have an error when I used pyqrcode.

[root@localhost python2.6]# python

Python 2.6.5 (r265:79063, Sep  7 2010, 07:31:57) 

[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import qrcode

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/local/lib/python2.6/site-packages/qrcode-0.2.1-py2.6-linux-x86_64.egg/qrcode/__init__.py", line 6, in <module>

    from qrcode import _qrcode

ImportError: cannot import name _qrcode

How to resolve the above error?

I refer to pyqrcode from http://pyqrcode.sourceforge.net/

Thanks Mana

+3
source share
1 answer

After the installation PIL-1.1.7, and JCC-2.14I tried to install pyqrcode-0.2.1from sources you, but also faced with the same error: ImportError: No module named _qrcode. But then I noticed what _qrcodelib ( _qrcode.so) really is . So I tried adding it to my library path:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/python2.7/site-packages/qrcode-0.2.1-py2.7-linux-x86_64.egg/qrcode/

And it worked! Well, actually, not really, I ran into another error:

AttributeError: 'module' object has no attribute '_setExceptionTypes'

So I edited the file __init__.py

# probably located under a path like this for linux
/usr/local/lib/python2.7/site-packages/qrcode-0.2.1-py2.7-linux-x86_64.egg/qrcode/

# or under a path like this for a Mac
/Library/Python/2.7/site-packages/qrcode-0.2.1-py2.7-macosx-10.7-intel.egg/qrcode/

and commented on line 21:

#  _qrcode._setExceptionTypes(JavaError, InvalidArgsError)

Then I was able to run their simple example:

#!/usr/bin/env python
# coding: utf-8
#
# pyqrcode sample encoder

import sys, qrcode

e = qrcode.Encoder()
image = e.encode('woah!', version=15, mode=e.mode.BINARY, eclevel=e.eclevel.H)
image.save('out.png')

(: http://pyqrcode.sourceforge.net/)

, ,

+1

Source: https://habr.com/ru/post/1770695/


All Articles