python二维码库pyqrcode-0.2.1安装使用

来源:互联网 发布:百度地图js touchend 编辑:程序博客网 时间:2024/06/05 15:26

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:

  1. Download and install JCC

  2. Download and install Python Imaging Library

  3. All the others (including java) are already built in


Instructions for Ubuntu Linux 8.10:

  1. Install JCC

  2. Install Java JDK and JRE

  3. Install Python Imaging Library

  4. Install Python setuptools

  5. Install Python development files

  6. 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


The resulting python egg will be built in the dist sub-directory of pyqrcode’s source tree.

使用

pyqrcode 是 Python 的扩展用来生成二维条形码以及对二维条形码进行解码。示例代码:#!/usr/bin/env python# coding: utf-8# pyqrcode sample encoderimport sys, qrcodee = 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:

  1. width: integer (default 400)

  2. border: integer (default 10)

  3. version: integer, from 1 to 40 (default 5)

  4. mode: NUMERIC, ALNUM, BINARY or KANJI (default ALNUM)

  5. eclevel: L, M, Q or H (default L)

  6. 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中的那一行注释掉即可

0 0