PIL图片show()在Windows 7上不起作用 [英] PIL image show() doesn't work on windows 7

查看:91
本文介绍了PIL图片show()在Windows 7上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows和其他平台上使用python显示图像. 当我这样做时:

I would like to show an image using python on windows and other platforms. When I do:

from PIL import Image
im = Image.open('image.png')
im.show()

我的默认查看器打开,并告诉我Windows Photo Viewer can't open this picture because either this file was deleted等.

my default viewer opens up and tells me that Windows Photo Viewer can't open this picture because either this file was deleted , etc.

该文件可能已删除,因为PIL使用以下命令调用os:"start /wait %s && del /f %s" % (file, file)

The file is probably deleted because PIL calls the os with the following command: "start /wait %s && del /f %s" % (file, file)

我找到了一种解决方法. 但是,我希望其他人能够使用我的代码.

I found a workaround here. They recommend changing PIL's code to "start /wait %s && PING 127.0.0.1 -n 5 > NUL && del /f %s" % (file, file). However, I want others to be able to use my code.

有一个简单的解决方案吗?我是否应该寻找可以跨平台使用的PIL替代方案?

Is there a simple solution? Should I look for an alternative to PIL that would work crossplatform?

推荐答案

好,在此处:

import webbrowser
webbrowser.open('image.png')

它将在我的计算机上打开默认查看器,而不是浏览器.

It opens the default viewer, not the browser, on my machine.

还有os.startfile.

这篇关于PIL图片show()在Windows 7上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆