环境:ubuntu14.04
今天想试试python生成二维码,找了篇博客试试:
http://www.jb51.net/article/58579.htm
1,先学着安装qrcode等:
$ sudo easy_install pil
$ sudo easy_install qrcode
2,在终端测试
$ qr "hello world" > test.png
报错:
... ...
IOError: encoder zip not available
百度,找到解决办法:http://codingnow.cn/language/208.html
1,安装需要的插件:
sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
2,查找PIL位置:
$ sudo easy_install -m pil
Searching for pil
Best match: PIL 1.1.7
Using /usr/local/lib/python2.7/dist-packages/PIL
... ...
3,删除PIL
sudo rm -r /usr/local/lib/python2.7/dist-packages/PIL
4,重装pil
sudo easy_install pil
5,测试
$ qr "hello world" > test.png
生成二维码成功;
再找个python的简单例子:http://www.cnblogs.com/linjiqin/p/4140455.html
import qrcode
img = qrcode.make('hello, qrcode')
img.save('test2.png')
运行后,同样生成二维码成功。