ubuntu Python2.7 安装PIL问题

$sudo easy_install PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
_imaging.c:75:20: fatal error: Python.h: 没有那个文件或目录
 #include "Python.h"
                    ^
compilation terminated.
error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

通过easy_install 安装PIL提示以上错误,解决方法:

$ sudo apt-get install python-dev

再次安装PIL成功。

测试:将一个图片生成缩略图:

#!/usr/bin/env python

from PIL import Image

im = Image.open('test.jpg')

print im.format, im.size, im.mode


im.thumbnail((120,120))


im.save('thumb.jpg', 'JPEG')
原文地址:https://www.cnblogs.com/yshyee/p/3825732.html