python - PIL 图像显示 () 在 Windows 7 上不起作用

标签 python windows-7 python-imaging-library show

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

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

我的默认查看器打开并告诉我 Windows 照片查看器无法打开此图片,因为此文件已被删除 等。

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

我找到了解决方法 here .他们建议将 PIL 的代码更改为 "start/wait %s && PING 127.0.0.1 -n 5 > NUL && del/f %s"% (file, file)。 但是,我希望其他人能够使用我的代码。

有没有简单的解决办法?我是否应该寻找可以跨平台工作的 PIL 替代品?

最佳答案

好的,找到解决方案here :

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

它会在我的机器上打开默认查看器,而不是浏览器。

此外,还有 os.startfile

关于python - PIL 图像显示 () 在 Windows 7 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7715501/

相关文章:

asp.net - IIS 7.5,ASP.NET,模拟和对C :\Windows\Temp的访问

Windows 7 任务栏进度在一个应用程序中有效,但在另一个应用程序中无效

python - PIL 使用转义序列在图像上写入文本

python 3.+,根据数据透视表中的平均价格创建一个新的分类列

python - 使用 Sphinx doc 记录 CLI 命令

Python - 如何根据分度计将列中的单元格拆分为新行

python - 使用 Python+PIL 对图像进行强度归一化 - 速度问题

python - python 中的异常。给定了定义,如何在代码中调用它?

WCF 适用于 XP 但不适用于 Windows 7

python - 使用 Python Pillow 的镜头模糊效果