为什么IPython.display.Image没有显示在输出中? [英] Why is IPython.display.Image not showing in output?
问题描述
我有一个像这样的单元格:
I have a cell that looks like this:
from IPython.display import Image
i = Image(filename='test.png')
i
print("test")
输出为:
test
我在输出中看不到图像.我检查了该文件是否存在(无论如何,如果不存在,则会出现错误).
I don't see the image in the output. I checked to see that the file exists (anyway, if it did not exist, you get an error).
有任何线索吗?
推荐答案
使用
i = Image(filename='test.png')
仅创建要显示的对象.通过以下两个操作之一显示对象:
only creates the object to display. Objects are displayed by one of two actions:
-
直接调用
IPython.display.display(obj)
,例如
from IPython.display import display
display(i)
displayhook
,它会自动显示单元格的 result ,也就是说将 i
放在上单元格的最后一行.您的示例中唯一的 i
不会显示,因为它不是单元格中的最后一件事.因此,虽然这不会显示图像:
the displayhook
, which automatically displays the result of the cell, which is to say putting i
on the last line of the cell. The lone i
in your example doesn't display because it is not the last thing in the cell. So while this doesn't display the image:
i = Image(filename='test.png')
i
print("test")
这将:
i = Image(filename='test.png')
print("test")
i
这篇关于为什么IPython.display.Image没有显示在输出中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!