ubuntu14.04环境下python3 Image.show()不显示图片问题

来源:互联网 发布:搭建阿里云服务器 编辑:程序博客网 时间:2024/06/05 15:43

  我使用了python3.4,Pillow2.9。但在使用下面代码时,show()没有动作。

from PIL import Imageimage = Image.open('captcha.gif')image.show()

查了好久,才在是stackoverflow上找到解决方法。分两种:

1 安装imagemagick: sudo apt-get install imagemagick。

2 修改Pillow文件:在ImageShow.py(位置在usr/local/lib/python3.4/dist-packages的Pillow-2.9.0~.egg中)代码片段中把"display"替换为"eog"。其中display时imagemagick的命令行启动命令,eog则是系统默认图片查看器的。

   class DisplayViewer(UnixViewer):        def get_command_ex(self, file, **options):            command = executable = "display"            return command, executable    if which("display"):        register(DisplayViewer)


两者相比,第一个方法很方便、简单。第二个方法没有成功,因为我无法修改ImageShow.py文件。


参考stackoverflow的热情解答:http://stackoverflow.com/questions/16279441/image-show-wont-display-the-picture





1 0
原创粉丝点击