环境:ubuntu14.04
今天想试试Python生成二维码:
1,先学着安装qrcode等:
$ sudo easy_install pil
$ sudo easy_install qrcode
2,在终端测试
$ qr "hello world" > test.png
报错:
... ...
IOError: encoder zip not available
找到解决办法:
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的简单例子:
import qrcode
img = qrcode.make('hello, qrcode')
img.save('test2.png')
运行后,同样生成二维码成功。