http://www.oschina.net/p/pyqrcode
http://pyqrcode.sourceforge.net/
源码安装
Basically, you’ll need JCC, a Java Development Kit (JDK) for building the source code, and a Java Runtime Environment (JRE) for using the resulting python extension. Also, you’ll needGNU make,Python Imaging Library, Python setuptools and Python development files.
Instructions for Mac OS X 10.5:
-
• Download and install JCC
-
• Download and install Python Imaging Library
-
• All the others (including java) are already built in
Instructions for Ubuntu Linux 8.10:
-
• Install JCC
-
• Install Java JDK and JRE
-
• Install Python Imaging Library
-
• Install Python setuptools
-
• Install Python development files
-
• Take a look at the “notes” below
$ sudo apt-get install jcc sun-java6-sdk python-imaging \
python-setuptools python-dev
Once the requirements are satisfied, you’re ready to get it to work. The Makefile has a couple of options, but the regular way also works fine.
$ make && sudo make install
Building binary distribution of the pyqrcode python extension is also available. In order to generate the python egg, run the following command:
$ make egg
使用
pyqrcode 是 Python 的扩展用来生成二维条形码以及对二维条形码进行解码。
示例代码:
#!/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')
Make sure you have a Java Runtime Environment (JRE) compatible with the pyqrcode python extension installed on your system.
For encoding, you have a couple of options:
-
• width: integer (default 400)
-
• border: integer (default 10)
-
• version: integer, from 1 to 40 (default 5)
-
• mode: NUMERIC, ALNUM, BINARY or KANJI (default ALNUM)
-
• eclevel: L, M, Q or H (default L)
-
• case_sensitive: True or False (default True)
运行:
python test.py
遇到问题:
参考:http://stackoverflow.com/questions/3986011/qrcode-for-python-on-linux
Traceback (most recent call last):
File "./test.py", line 5, in <module>
import sys, qrcode
File "/usr/local/lib/python2.7/dist-packages/qrcode-0.2.1-py2.7-linux-x86_64.egg/qrcode/__init__.py", line 21, in <module>
_qrcode._setExceptionTypes(JavaError, InvalidArgsError)
AttributeError: 'module' object has no attribute '_setExceptionTypes'
把__init__.py中的那一行注释掉即可
本文介绍了如何在不同操作系统上安装并使用pyqrcode Python扩展来生成二维条形码,包括源码安装步骤、示例代码及常见问题解决。
359

被折叠的 条评论
为什么被折叠?



