我已经设置了默认的应用程序——gimp,以便在操作系统中打开图像(debian 11+lxde)。
下面的python代码将在默认的图像查看器中打开图像,如下所示: open a new window to show image
>>> from PIL import Image >>> img = Image.open('test.png') >>> img.show()
为什么在我的操作系统中执行时没有打开新窗口,gimp开始显示图像?
在Debian运行中安装matplotlib sudo apt install python3-matplotlib 。使用matplotlib Python模块中的pyplot显示图像,如下所示。
sudo apt install python3-matplotlib
import matplotlib.pyplot as plt from PIL import Image plt.imshow(Image.open('test.png')) plt.show()
或者使用安装eog sudo apt install eog 并且您的原始代码将在新窗口中显示图像。请注意,如果图像很小,那么新窗口也会很小,您可能不会注意到它是打开的。
sudo apt install eog