我使用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
如何解决上述错误?
我指的是来自http://pyqrcode.sourceforge.net/
的pyqrcode谢谢, 马努
答案 0 :(得分:1)
安装PIL-1.1.7
和JCC-2.14
后,我尝试从您的来源安装pyqrcode-0.2.1
,并遇到了同样的错误:
ImportError: No module named _qrcode
。但后来我注意到_qrcode
实际上是一个lib(_qrcode.so
)。所以我试图在我的库路径上添加它:
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/
它有效!实际上,不完全是,我遇到了另一个错误:
AttributeError: 'module' object has no attribute '_setExceptionTypes'
所以我编辑了__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/
并注释掉第21行:
# _qrcode._setExceptionTypes(JavaError, InvalidArgsError)
然后我能够运行他们的简单例子:
#!/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/)
希望它有所帮助,