PIL image show() doesn#39;t work on windows 7(PIL 图像显示()在 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 照片查看器无法打开此图片,因为此文件已被删除 等等.
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 使用以下命令调用操作系统:"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)
我找到了一种解决方法 这里.他们建议将 PIL 的代码更改为 "start/wait %s && PING 127.0.0.1 -n 5 > NUL && 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 图像显示()在 Windows 7 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PIL 图像显示()在 Windows 7 上不起作用
基础教程推荐
- Discord.py 缺少必需的参数 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
